From 9f57903e9cdafda3e32ce0e3472ad7fe2a9c1e3a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 6 Apr 2025 14:38:16 +0200 Subject: [PATCH] Insert adjustments incrementally --- compiler/rustc_hir_typeck/src/pat.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index e6e262279cd..70eb21ca356 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -354,13 +354,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // type into the adjustments vector. // // See the examples in `ui/match-defbm*.rs`. - let mut pat_adjustments = vec![]; while let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() { debug!("inspecting {:?}", expected); debug!("current discriminant is Ref, inserting implicit deref"); // Preserve the reference type. We'll need it later during THIR lowering. - pat_adjustments.push(expected); + self.typeck_results + .borrow_mut() + .pat_adjustments_mut() + .entry(pat.hir_id) + .or_default() + .push(expected); expected = self.try_structurally_resolve_type(pat.span, inner_ty); binding_mode = ByRef::Yes(match binding_mode { @@ -382,13 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { max_ref_mutbl = MutblCap::Not; } - if !pat_adjustments.is_empty() { - debug!("default binding mode is now {:?}", binding_mode); - self.typeck_results - .borrow_mut() - .pat_adjustments_mut() - .insert(pat.hir_id, pat_adjustments); - } + debug!("default binding mode is now {:?}", binding_mode); (expected, binding_mode, max_ref_mutbl) }