@@ -460,19 +460,17 @@ pub struct InferenceResult {
460460 /// Whenever a tuple field expression access a tuple field, we allocate a tuple id in
461461 /// [`InferenceContext`] and store the tuples substitution there. This map is the reverse of
462462 /// that which allows us to resolve a [`TupleFieldId`]s type.
463- pub tuple_field_access_types : FxHashMap < TupleId , Substitution > ,
463+ tuple_field_access_types : FxHashMap < TupleId , Substitution > ,
464464 /// During inference this field is empty and [`InferenceContext::diagnostics`] is filled instead.
465- pub diagnostics : Vec < InferenceDiagnostic > ,
466- pub type_of_expr : ArenaMap < ExprId , Ty > ,
465+ diagnostics : Vec < InferenceDiagnostic > ,
466+ pub ( crate ) type_of_expr : ArenaMap < ExprId , Ty > ,
467467 /// For each pattern record the type it resolves to.
468468 ///
469469 /// **Note**: When a pattern type is resolved it may still contain
470470 /// unresolved or missing subpatterns or subpatterns of mismatched types.
471- pub type_of_pat : ArenaMap < PatId , Ty > ,
472- pub type_of_binding : ArenaMap < BindingId , Ty > ,
473- pub type_of_rpit : ArenaMap < ImplTraitIdx , Ty > ,
474- /// Type of the result of `.into_iter()` on the for. `ExprId` is the one of the whole for loop.
475- pub type_of_for_iterator : FxHashMap < ExprId , Ty > ,
471+ pub ( crate ) type_of_pat : ArenaMap < PatId , Ty > ,
472+ pub ( crate ) type_of_binding : ArenaMap < BindingId , Ty > ,
473+ pub ( crate ) type_of_rpit : ArenaMap < ImplTraitIdx , Ty > ,
476474 type_mismatches : FxHashMap < ExprOrPatId , TypeMismatch > ,
477475 /// Whether there are any type-mismatching errors in the result.
478476 // FIXME: This isn't as useful as initially thought due to us falling back placeholders to
@@ -483,7 +481,7 @@ pub struct InferenceResult {
483481 // FIXME: Move this into `InferenceContext`
484482 standard_types : InternedStandardTypes ,
485483 /// Stores the types which were implicitly dereferenced in pattern binding modes.
486- pub pat_adjustments : FxHashMap < PatId , Vec < Ty > > ,
484+ pub ( crate ) pat_adjustments : FxHashMap < PatId , Vec < Ty > > ,
487485 /// Stores the binding mode (`ref` in `let ref x = 2`) of bindings.
488486 ///
489487 /// This one is tied to the `PatId` instead of `BindingId`, because in some rare cases, a binding in an
@@ -497,12 +495,12 @@ pub struct InferenceResult {
497495 /// }
498496 /// ```
499497 /// the first `rest` has implicit `ref` binding mode, but the second `rest` binding mode is `move`.
500- pub binding_modes : ArenaMap < PatId , BindingMode > ,
501- pub expr_adjustments : FxHashMap < ExprId , Box < [ Adjustment ] > > ,
498+ pub ( crate ) binding_modes : ArenaMap < PatId , BindingMode > ,
499+ pub ( crate ) expr_adjustments : FxHashMap < ExprId , Box < [ Adjustment ] > > ,
502500 pub ( crate ) closure_info : FxHashMap < ClosureId , ( Vec < CapturedItem > , FnTrait ) > ,
503501 // FIXME: remove this field
504502 pub mutated_bindings_in_closure : FxHashSet < BindingId > ,
505- pub coercion_casts : FxHashSet < ExprId > ,
503+ pub ( crate ) coercion_casts : FxHashSet < ExprId > ,
506504}
507505
508506impl InferenceResult {
@@ -566,6 +564,26 @@ impl InferenceResult {
566564 pub fn is_erroneous ( & self ) -> bool {
567565 self . has_errors && self . type_of_expr . iter ( ) . count ( ) == 0
568566 }
567+
568+ pub fn diagnostics ( & self ) -> & [ InferenceDiagnostic ] {
569+ & self . diagnostics
570+ }
571+
572+ pub fn tuple_field_access_type ( & self , id : TupleId ) -> & Substitution {
573+ & self . tuple_field_access_types [ & id]
574+ }
575+
576+ pub fn pat_adjustment ( & self , id : PatId ) -> Option < & [ Ty ] > {
577+ self . pat_adjustments . get ( & id) . map ( |it| & * * it)
578+ }
579+
580+ pub fn expr_adjustment ( & self , id : ExprId ) -> Option < & [ Adjustment ] > {
581+ self . expr_adjustments . get ( & id) . map ( |it| & * * it)
582+ }
583+
584+ pub fn binding_mode ( & self , id : PatId ) -> Option < BindingMode > {
585+ self . binding_modes . get ( id) . copied ( )
586+ }
569587}
570588
571589impl Index < ExprId > for InferenceResult {
@@ -772,7 +790,6 @@ impl<'db> InferenceContext<'db> {
772790 type_of_pat,
773791 type_of_binding,
774792 type_of_rpit,
775- type_of_for_iterator,
776793 type_mismatches,
777794 has_errors,
778795 standard_types : _,
@@ -832,11 +849,6 @@ impl<'db> InferenceContext<'db> {
832849 * has_errors = * has_errors || ty. contains_unknown ( ) ;
833850 }
834851 type_of_rpit. shrink_to_fit ( ) ;
835- for ty in type_of_for_iterator. values_mut ( ) {
836- * ty = table. resolve_completely ( ty. clone ( ) ) ;
837- * has_errors = * has_errors || ty. contains_unknown ( ) ;
838- }
839- type_of_for_iterator. shrink_to_fit ( ) ;
840852
841853 * has_errors |= !type_mismatches. is_empty ( ) ;
842854
0 commit comments