@@ -493,7 +493,7 @@ pub struct InferenceResult {
493493 /// ```
494494 /// the first `rest` has implicit `ref` binding mode, but the second `rest` binding mode is `move`.
495495 pub binding_modes : ArenaMap < PatId , BindingMode > ,
496- pub expr_adjustments : FxHashMap < ExprId , Vec < Adjustment > > ,
496+ pub expr_adjustments : FxHashMap < ExprId , Box < [ Adjustment ] > > ,
497497 pub ( crate ) closure_info : FxHashMap < ClosureId , ( Vec < CapturedItem > , FnTrait ) > ,
498498 // FIXME: remove this field
499499 pub mutated_bindings_in_closure : FxHashSet < BindingId > ,
@@ -785,8 +785,8 @@ impl<'a> InferenceContext<'a> {
785785 // Comment from rustc:
786786 // Even though coercion casts provide type hints, we check casts after fallback for
787787 // backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
788- let mut apply_adjustments = |expr, adj| {
789- expr_adjustments. insert ( expr, adj) ;
788+ let mut apply_adjustments = |expr, adj : Vec < _ > | {
789+ expr_adjustments. insert ( expr, adj. into_boxed_slice ( ) ) ;
790790 } ;
791791 let mut set_coercion_cast = |expr| {
792792 coercion_casts. insert ( expr) ;
@@ -808,22 +808,27 @@ impl<'a> InferenceContext<'a> {
808808 * ty = table. resolve_completely ( ty. clone ( ) ) ;
809809 * has_errors = * has_errors || ty. contains_unknown ( ) ;
810810 }
811+ type_of_expr. shrink_to_fit ( ) ;
811812 for ty in type_of_pat. values_mut ( ) {
812813 * ty = table. resolve_completely ( ty. clone ( ) ) ;
813814 * has_errors = * has_errors || ty. contains_unknown ( ) ;
814815 }
816+ type_of_pat. shrink_to_fit ( ) ;
815817 for ty in type_of_binding. values_mut ( ) {
816818 * ty = table. resolve_completely ( ty. clone ( ) ) ;
817819 * has_errors = * has_errors || ty. contains_unknown ( ) ;
818820 }
821+ type_of_binding. shrink_to_fit ( ) ;
819822 for ty in type_of_rpit. values_mut ( ) {
820823 * ty = table. resolve_completely ( ty. clone ( ) ) ;
821824 * has_errors = * has_errors || ty. contains_unknown ( ) ;
822825 }
826+ type_of_rpit. shrink_to_fit ( ) ;
823827 for ty in type_of_for_iterator. values_mut ( ) {
824828 * ty = table. resolve_completely ( ty. clone ( ) ) ;
825829 * has_errors = * has_errors || ty. contains_unknown ( ) ;
826830 }
831+ type_of_for_iterator. shrink_to_fit ( ) ;
827832
828833 * has_errors |= !type_mismatches. is_empty ( ) ;
829834
@@ -838,6 +843,7 @@ impl<'a> InferenceContext<'a> {
838843 )
839844 . is_ok ( )
840845 } ) ;
846+ type_mismatches. shrink_to_fit ( ) ;
841847 diagnostics. retain_mut ( |diagnostic| {
842848 use InferenceDiagnostic :: * ;
843849 match diagnostic {
@@ -866,24 +872,29 @@ impl<'a> InferenceContext<'a> {
866872 }
867873 true
868874 } ) ;
875+ diagnostics. shrink_to_fit ( ) ;
869876 for ( _, subst) in method_resolutions. values_mut ( ) {
870877 * subst = table. resolve_completely ( subst. clone ( ) ) ;
871878 * has_errors =
872879 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
873880 }
881+ method_resolutions. shrink_to_fit ( ) ;
874882 for ( _, subst) in assoc_resolutions. values_mut ( ) {
875883 * subst = table. resolve_completely ( subst. clone ( ) ) ;
876884 * has_errors =
877885 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
878886 }
887+ assoc_resolutions. shrink_to_fit ( ) ;
879888 for adjustment in expr_adjustments. values_mut ( ) . flatten ( ) {
880889 adjustment. target = table. resolve_completely ( adjustment. target . clone ( ) ) ;
881890 * has_errors = * has_errors || adjustment. target . contains_unknown ( ) ;
882891 }
892+ expr_adjustments. shrink_to_fit ( ) ;
883893 for adjustment in pat_adjustments. values_mut ( ) . flatten ( ) {
884894 * adjustment = table. resolve_completely ( adjustment. clone ( ) ) ;
885895 * has_errors = * has_errors || adjustment. contains_unknown ( ) ;
886896 }
897+ pat_adjustments. shrink_to_fit ( ) ;
887898 result. tuple_field_access_types = tuple_field_accesses_rev
888899 . into_iter ( )
889900 . enumerate ( )
@@ -893,6 +904,7 @@ impl<'a> InferenceContext<'a> {
893904 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
894905 } )
895906 . collect ( ) ;
907+ result. tuple_field_access_types . shrink_to_fit ( ) ;
896908
897909 result. diagnostics = diagnostics;
898910
@@ -1261,7 +1273,7 @@ impl<'a> InferenceContext<'a> {
12611273 self . result . type_of_expr . insert ( expr, ty) ;
12621274 }
12631275
1264- fn write_expr_adj ( & mut self , expr : ExprId , adjustments : Vec < Adjustment > ) {
1276+ fn write_expr_adj ( & mut self , expr : ExprId , adjustments : Box < [ Adjustment ] > ) {
12651277 if adjustments. is_empty ( ) {
12661278 return ;
12671279 }
0 commit comments