pub struct InferenceResult<'db> {Show 21 fields
method_resolutions: FxHashMap<ExprId, (FunctionId, StoredGenericArgs)>,
field_resolutions: FxHashMap<ExprId, Either<FieldId, TupleFieldId>>,
variant_resolutions: FxHashMap<ExprOrPatIdPacked, VariantId>,
assoc_resolutions: FxHashMap<ExprOrPatIdPacked, (CandidateId, StoredGenericArgs)>,
tuple_field_access_types: ThinVec<StoredTys>,
pub(crate) type_of_expr: ArenaMap<ExprId, StoredTy>,
pub(crate) type_of_pat: ArenaMap<PatId, StoredTy>,
pub(crate) type_of_binding: ArenaMap<BindingId, StoredTy>,
pub(crate) type_of_type_placeholder: FxHashMap<TypeRefId, StoredTy>,
pub(crate) type_of_opaque: FxHashMap<InternedOpaqueTyId<'db>, StoredTy>,
pub(crate) has_errors: bool,
diagnostics: ThinVec<InferenceDiagnostic>,
nodes_with_type_mismatches: Option<Box<FxHashSet<ExprOrPatIdPacked>>>,
error_ty: StoredTy,
pub(crate) expr_adjustments: FxHashMap<ExprId, Box<[Adjustment]>>,
pub(crate) pat_adjustments: FxHashMap<PatId, Vec<PatAdjustment>>,
pub(crate) binding_modes: ArenaMap<PatId, BindingMode>,
skipped_ref_pats: FxHashSet<PatId>,
pub(crate) coercion_casts: FxHashSet<ExprId>,
pub closures_data: FxHashMap<ExprId, ClosureData>,
defined_anon_consts: ThinVec<AnonConstId<'db>>,
}Expand description
The result of type inference: A mapping from expressions and patterns to types.
When you add a field that stores types (including Substitution and the like), don’t forget
resolve_completely()’ing them in InferenceContext::resolve_all(). Inference variables must
not appear in the final inference result.
Fields§
§method_resolutions: FxHashMap<ExprId, (FunctionId, StoredGenericArgs)>For each method call expr, records the function it resolves to.
field_resolutions: FxHashMap<ExprId, Either<FieldId, TupleFieldId>>For each field access expr, records the field it resolves to.
variant_resolutions: FxHashMap<ExprOrPatIdPacked, VariantId>For each struct literal or pattern, records the variant it resolves to.
assoc_resolutions: FxHashMap<ExprOrPatIdPacked, (CandidateId, StoredGenericArgs)>For each associated item record what it resolves to
tuple_field_access_types: ThinVec<StoredTys>Whenever a tuple field expression access a tuple field, we allocate a tuple id in
InferenceContext and store the tuples substitution there. This map is the reverse of
that which allows us to resolve a [TupleFieldId]s type.
type_of_expr: ArenaMap<ExprId, StoredTy>§type_of_pat: ArenaMap<PatId, StoredTy>For each pattern record the type it resolves to.
Note: When a pattern type is resolved it may still contain unresolved or missing subpatterns or subpatterns of mismatched types.
type_of_binding: ArenaMap<BindingId, StoredTy>§type_of_type_placeholder: FxHashMap<TypeRefId, StoredTy>§type_of_opaque: FxHashMap<InternedOpaqueTyId<'db>, StoredTy>§has_errors: boolWhether there are any type-mismatching errors in the result.
diagnostics: ThinVec<InferenceDiagnostic>During inference this field is empty and InferenceContext::diagnostics is filled instead.
nodes_with_type_mismatches: Option<Box<FxHashSet<ExprOrPatIdPacked>>>§error_ty: StoredTyInterned Error type to return references to.
expr_adjustments: FxHashMap<ExprId, Box<[Adjustment]>>§pat_adjustments: FxHashMap<PatId, Vec<PatAdjustment>>Stores the types which were implicitly dereferenced in pattern binding modes.
binding_modes: ArenaMap<PatId, BindingMode>Stores the binding mode (ref in let ref x = 2) of bindings.
This one is tied to the PatId instead of BindingId, because in some rare cases, a binding in an
or pattern can have multiple binding modes. For example:
fn foo(mut slice: &[u32]) -> usize {
slice = match slice {
[0, rest @ ..] | rest => rest,
};
0
}the first rest has implicit ref binding mode, but the second rest binding mode is move.
skipped_ref_pats: FxHashSet<PatId>Set of reference patterns that match against a match-ergonomics inserted reference (as opposed to against a reference in the scrutinee type).
coercion_casts: FxHashSet<ExprId>§closures_data: FxHashMap<ExprId, ClosureData>§defined_anon_consts: ThinVec<AnonConstId<'db>>Implementations§
Source§impl<'db> InferenceResult<'db>
impl<'db> InferenceResult<'db>
fn for_body( db: &'db dyn HirDatabase, def: DefWithBodyId, ) -> &'db InferenceResult<'db>
Source§impl<'db> InferenceResult<'db>
impl<'db> InferenceResult<'db>
Sourcefn for_anon_const(
db: &'db dyn HirDatabase,
def: AnonConstId<'db>,
) -> &'db InferenceResult<'db>
fn for_anon_const( db: &'db dyn HirDatabase, def: AnonConstId<'db>, ) -> &'db InferenceResult<'db>
Infer types for all const expressions in an item’s signature.
Returns an InferenceResult containing type information for array lengths,
const generic arguments, and other const expressions appearing in type
positions within the item’s signature.
Source§impl<'db> InferenceResult<'db>
impl<'db> InferenceResult<'db>
pub fn of( db: &'db dyn HirDatabase, def: impl Into<InferBodyId<'db>>, ) -> &'db InferenceResult<'db>
Source§impl<'db> InferenceResult<'db>
impl<'db> InferenceResult<'db>
fn new(error_ty: Ty<'_>) -> Self
pub fn method_resolution( &self, expr: ExprId, ) -> Option<(FunctionId, GenericArgs<'db>)>
pub fn field_resolution( &self, expr: ExprId, ) -> Option<Either<FieldId, TupleFieldId>>
pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId>
pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantId>
pub fn variant_resolution_for_expr_or_pat( &self, id: ExprOrPatId, ) -> Option<VariantId>
pub fn assoc_resolutions_for_expr<'a>( &self, id: ExprId, ) -> Option<(CandidateId, GenericArgs<'a>)>
pub fn assoc_resolutions_for_pat<'a>( &self, id: PatId, ) -> Option<(CandidateId, GenericArgs<'a>)>
pub fn assoc_resolutions_for_expr_or_pat<'a>( &self, id: ExprOrPatId, ) -> Option<(CandidateId, GenericArgs<'a>)>
pub fn expr_or_pat_has_type_mismatch(&self, node: ExprOrPatIdPacked) -> bool
pub fn expr_has_type_mismatch(&self, expr: ExprId) -> bool
pub fn pat_has_type_mismatch(&self, pat: PatId) -> bool
pub fn exprs_have_type_mismatches(&self) -> bool
pub fn has_type_mismatches(&self) -> bool
pub fn placeholder_types<'a>(&self) -> impl Iterator<Item = (TypeRefId, Ty<'a>)>
pub fn type_of_type_placeholder<'a>( &self, type_ref: TypeRefId, ) -> Option<Ty<'a>>
pub fn type_of_expr_or_pat<'a>(&self, id: ExprOrPatId) -> Option<Ty<'a>>
pub fn type_of_expr_with_adjust<'a>(&self, id: ExprId) -> Option<Ty<'a>>
pub fn type_of_pat_with_adjust<'a>(&self, id: PatId) -> Ty<'a>
pub fn is_erroneous(&self) -> bool
pub fn diagnostics(&self) -> &[InferenceDiagnostic]
pub fn tuple_field_access_type<'a>(&self, id: TupleId) -> Tys<'a>
pub fn pat_adjustment(&self, id: PatId) -> Option<&[PatAdjustment]>
pub fn expr_adjustment(&self, id: ExprId) -> Option<&[Adjustment]>
pub fn binding_mode(&self, id: PatId) -> Option<BindingMode>
pub fn expression_types<'a>(&self) -> impl Iterator<Item = (ExprId, Ty<'a>)>
pub fn pattern_types<'a>(&self) -> impl Iterator<Item = (PatId, Ty<'a>)>
pub fn binding_types<'a>(&self) -> impl Iterator<Item = (BindingId, Ty<'a>)>
pub fn return_position_impl_trait_types<'a>( &'a self, db: &'a dyn HirDatabase, ) -> impl Iterator<Item = (ImplTraitIdx, Ty<'a>)>
pub fn expr_ty<'a>(&self, id: ExprId) -> Ty<'a>
pub fn pat_ty<'a>(&self, id: PatId) -> Ty<'a>
pub fn expr_or_pat_ty<'a>(&self, id: ExprOrPatId) -> Ty<'a>
pub fn binding_ty<'a>(&self, id: BindingId) -> Ty<'a>
Sourcepub fn closure_captures_tys<'a>(
&self,
closure: ExprId,
) -> impl Iterator<Item = Ty<'a>>
pub fn closure_captures_tys<'a>( &self, closure: ExprId, ) -> impl Iterator<Item = Ty<'a>>
This does not deduplicate, which means you’ll get the types once per capture.
Sourcepub fn closure_captures_captured_tys<'a>(
&self,
db: &'a dyn HirDatabase,
closure: ExprId,
) -> impl Iterator<Item = Ty<'a>>
pub fn closure_captures_captured_tys<'a>( &self, db: &'a dyn HirDatabase, closure: ExprId, ) -> impl Iterator<Item = Ty<'a>>
Like Self::closure_captures_tys(), but using CapturedPlace::captured_ty().
pub fn is_skipped_ref_pat(&self, pat: PatId) -> bool
Trait Implementations§
Source§impl<'db> Clone for InferenceResult<'db>
impl<'db> Clone for InferenceResult<'db>
Source§fn clone(&self) -> InferenceResult<'db>
fn clone(&self) -> InferenceResult<'db>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'db> Debug for InferenceResult<'db>
impl<'db> Debug for InferenceResult<'db>
Source§impl<'db> PartialEq for InferenceResult<'db>
impl<'db> PartialEq for InferenceResult<'db>
Source§fn eq(&self, other: &InferenceResult<'db>) -> bool
fn eq(&self, other: &InferenceResult<'db>) -> bool
self and other values to be equal, and is used by ==.Source§impl<'db> Update for InferenceResult<'db>
impl<'db> Update for InferenceResult<'db>
impl<'db> Eq for InferenceResult<'db>
impl<'db> StructuralPartialEq for InferenceResult<'db>
Auto Trait Implementations§
impl<'db> Freeze for InferenceResult<'db>
impl<'db> RefUnwindSafe for InferenceResult<'db>
impl<'db> Send for InferenceResult<'db>
impl<'db> Sync for InferenceResult<'db>
impl<'db> Unpin for InferenceResult<'db>
impl<'db> UnsafeUnpin for InferenceResult<'db>
impl<'db> UnwindSafe for InferenceResult<'db>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more