@@ -460,9 +460,6 @@ pub struct InferenceResult {
460460 // `TyKind::Error`.
461461 // Which will then mark this field.
462462 pub ( crate ) has_errors : bool ,
463- /// Interned common types to return references to.
464- /// Stores the types which were implicitly dereferenced in pattern binding modes.
465- pub pat_adjustments : FxHashMap < PatId , Vec < Ty > > ,
466463 /// Stores the binding mode (`ref` in `let ref x = 2`) of bindings.
467464 ///
468465 /// This one is tied to the `PatId` instead of `BindingId`, because in some rare cases, a binding in an
@@ -477,7 +474,8 @@ pub struct InferenceResult {
477474 /// ```
478475 /// the first `rest` has implicit `ref` binding mode, but the second `rest` binding mode is `move`.
479476 pub binding_modes : ArenaMap < PatId , BindingMode > ,
480- pub expr_adjustments : FxHashMap < ExprId , Box < [ Adjustment ] > > ,
477+ /// For patterns, this stores the types which were implicitly dereferenced in pattern binding modes.
478+ adjustments : FxHashMap < ExprOrPatId , Box < [ Adjustment ] > > ,
481479 pub ( crate ) closure_info : FxHashMap < ClosureId , ( Vec < CapturedItem > , FnTrait ) > ,
482480 // FIXME: remove this field
483481 pub mutated_bindings_in_closure : FxHashSet < BindingId > ,
@@ -488,6 +486,12 @@ impl InferenceResult {
488486 pub fn method_resolution ( & self , expr : ExprId ) -> Option < ( FunctionId , Substitution ) > {
489487 self . method_resolutions . get ( & expr) . cloned ( )
490488 }
489+ pub fn pat_adjustments ( & self , pat : PatId ) -> & [ Adjustment ] {
490+ self . adjustments . get ( & ExprOrPatId :: PatId ( pat) ) . map_or ( & [ ] , |v| v. as_ref ( ) )
491+ }
492+ pub fn expr_adjustments ( & self , expr : ExprId ) -> & [ Adjustment ] {
493+ self . adjustments . get ( & ExprOrPatId :: ExprId ( expr) ) . map_or ( & [ ] , |v| v. as_ref ( ) )
494+ }
491495 pub fn field_resolution ( & self , expr : ExprId ) -> Option < Either < FieldId , TupleFieldId > > {
492496 self . field_resolutions . get ( & expr) . copied ( )
493497 }
@@ -751,9 +755,8 @@ impl<'db> InferenceContext<'db> {
751755 type_of_for_iterator,
752756 type_mismatches,
753757 has_errors,
754- pat_adjustments,
755758 binding_modes : _,
756- expr_adjustments ,
759+ adjustments ,
757760 // Types in `closure_info` have already been `resolve_completely()`'d during
758761 // `InferenceContext::infer_closures()` (in `HirPlace::ty()` specifically), so no need
759762 // to resolve them here.
@@ -769,7 +772,7 @@ impl<'db> InferenceContext<'db> {
769772 // Even though coercion casts provide type hints, we check casts after fallback for
770773 // backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
771774 let mut apply_adjustments = |expr, adj : Vec < _ > | {
772- expr_adjustments . insert ( expr, adj. into_boxed_slice ( ) ) ;
775+ adjustments . insert ( ExprOrPatId :: ExprId ( expr) , adj. into_boxed_slice ( ) ) ;
773776 } ;
774777 let mut set_coercion_cast = |expr| {
775778 coercion_casts. insert ( expr) ;
@@ -868,16 +871,11 @@ impl<'db> InferenceContext<'db> {
868871 * has_errors || subst. type_parameters ( Interner ) . any ( |ty| ty. contains_unknown ( ) ) ;
869872 }
870873 assoc_resolutions. shrink_to_fit ( ) ;
871- for adjustment in expr_adjustments . values_mut ( ) . flatten ( ) {
874+ for adjustment in adjustments . values_mut ( ) . flatten ( ) {
872875 adjustment. target = table. resolve_completely ( adjustment. target . clone ( ) ) ;
873876 * has_errors = * has_errors || adjustment. target . contains_unknown ( ) ;
874877 }
875- expr_adjustments. shrink_to_fit ( ) ;
876- for adjustment in pat_adjustments. values_mut ( ) . flatten ( ) {
877- * adjustment = table. resolve_completely ( adjustment. clone ( ) ) ;
878- * has_errors = * has_errors || adjustment. contains_unknown ( ) ;
879- }
880- pat_adjustments. shrink_to_fit ( ) ;
878+ adjustments. shrink_to_fit ( ) ;
881879 result. tuple_field_access_types = tuple_field_accesses_rev
882880 . into_iter ( )
883881 . enumerate ( )
@@ -1260,7 +1258,7 @@ impl<'db> InferenceContext<'db> {
12601258 if adjustments. is_empty ( ) {
12611259 return ;
12621260 }
1263- match self . result . expr_adjustments . entry ( expr) {
1261+ match self . result . adjustments . entry ( expr. into ( ) ) {
12641262 std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
12651263 match ( & mut entry. get_mut ( ) [ ..] , & adjustments[ ..] ) {
12661264 (
0 commit comments