@@ -460,19 +460,17 @@ pub struct InferenceResult {
460
460
/// Whenever a tuple field expression access a tuple field, we allocate a tuple id in
461
461
/// [`InferenceContext`] and store the tuples substitution there. This map is the reverse of
462
462
/// 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 > ,
464
464
/// 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 > ,
467
467
/// For each pattern record the type it resolves to.
468
468
///
469
469
/// **Note**: When a pattern type is resolved it may still contain
470
470
/// 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 > ,
476
474
type_mismatches : FxHashMap < ExprOrPatId , TypeMismatch > ,
477
475
/// Whether there are any type-mismatching errors in the result.
478
476
// FIXME: This isn't as useful as initially thought due to us falling back placeholders to
@@ -483,7 +481,7 @@ pub struct InferenceResult {
483
481
// FIXME: Move this into `InferenceContext`
484
482
standard_types : InternedStandardTypes ,
485
483
/// 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 > > ,
487
485
/// Stores the binding mode (`ref` in `let ref x = 2`) of bindings.
488
486
///
489
487
/// 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 {
497
495
/// }
498
496
/// ```
499
497
/// 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 ] > > ,
502
500
pub ( crate ) closure_info : FxHashMap < ClosureId , ( Vec < CapturedItem > , FnTrait ) > ,
503
501
// FIXME: remove this field
504
502
pub mutated_bindings_in_closure : FxHashSet < BindingId > ,
505
- pub coercion_casts : FxHashSet < ExprId > ,
503
+ pub ( crate ) coercion_casts : FxHashSet < ExprId > ,
506
504
}
507
505
508
506
impl InferenceResult {
@@ -566,6 +564,26 @@ impl InferenceResult {
566
564
pub fn is_erroneous ( & self ) -> bool {
567
565
self . has_errors && self . type_of_expr . iter ( ) . count ( ) == 0
568
566
}
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
+ }
569
587
}
570
588
571
589
impl Index < ExprId > for InferenceResult {
@@ -772,7 +790,6 @@ impl<'db> InferenceContext<'db> {
772
790
type_of_pat,
773
791
type_of_binding,
774
792
type_of_rpit,
775
- type_of_for_iterator,
776
793
type_mismatches,
777
794
has_errors,
778
795
standard_types : _,
@@ -832,11 +849,6 @@ impl<'db> InferenceContext<'db> {
832
849
* has_errors = * has_errors || ty. contains_unknown ( ) ;
833
850
}
834
851
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 ( ) ;
840
852
841
853
* has_errors |= !type_mismatches. is_empty ( ) ;
842
854
0 commit comments