|
| 1 | +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use rustc_data_structures::sync::Lrc; |
| 12 | +use infer::canonical::{Canonical, QueryResponse}; |
| 13 | +use ty::Ty; |
| 14 | + |
| 15 | +#[derive(Debug)] |
| 16 | +pub struct CandidateStep<'tcx> { |
| 17 | + pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>, |
| 18 | + pub autoderefs: usize, |
| 19 | + // true if the type results from a dereference of a raw pointer. |
| 20 | + // when assembling candidates, we include these steps, but not when |
| 21 | + // picking methods. This so that if we have `foo: *const Foo` and `Foo` has methods |
| 22 | + // `fn by_raw_ptr(self: *const Self)` and `fn by_ref(&self)`, then |
| 23 | + // `foo.by_raw_ptr()` will work and `foo.by_ref()` won't. |
| 24 | + pub from_unsafe_deref: bool, |
| 25 | + pub unsize: bool, |
| 26 | +} |
| 27 | + |
| 28 | +#[derive(Clone, Debug)] |
| 29 | +pub struct MethodAutoderefStepsResult<'tcx> { |
| 30 | + /// The valid autoderef steps that could be find. |
| 31 | + pub steps: Lrc<Vec<CandidateStep<'tcx>>>, |
| 32 | + /// If Some(T), a type autoderef reported an error on. |
| 33 | + pub opt_bad_ty: Option<Lrc<MethodAutoderefBadTy<'tcx>>>, |
| 34 | + /// If `true`, `steps` has been truncated due to reaching the |
| 35 | + /// recursion limit. |
| 36 | + pub reached_recursion_limit: bool, |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Debug)] |
| 40 | +pub struct MethodAutoderefBadTy<'tcx> { |
| 41 | + pub reached_raw_pointer: bool, |
| 42 | + pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>, |
| 43 | +} |
| 44 | + |
| 45 | +impl_stable_hash_for!(struct MethodAutoderefBadTy<'tcx> { |
| 46 | + reached_raw_pointer, ty |
| 47 | +}); |
| 48 | + |
| 49 | +impl_stable_hash_for!(struct MethodAutoderefStepsResult<'tcx> { |
| 50 | + reached_recursion_limit, steps, opt_bad_ty |
| 51 | +}); |
| 52 | + |
| 53 | +impl_stable_hash_for!(struct CandidateStep<'tcx> { |
| 54 | + self_ty, autoderefs, from_unsafe_deref, unsize |
| 55 | +}); |
0 commit comments