Skip to content

Commit 9f57903

Browse files
committed
Insert adjustments incrementally
1 parent a0d9c87 commit 9f57903

File tree

1 file changed

+7
-9
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+7
-9
lines changed

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
354354
// type into the adjustments vector.
355355
//
356356
// See the examples in `ui/match-defbm*.rs`.
357-
let mut pat_adjustments = vec![];
358357
while let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() {
359358
debug!("inspecting {:?}", expected);
360359

361360
debug!("current discriminant is Ref, inserting implicit deref");
362361
// Preserve the reference type. We'll need it later during THIR lowering.
363-
pat_adjustments.push(expected);
362+
self.typeck_results
363+
.borrow_mut()
364+
.pat_adjustments_mut()
365+
.entry(pat.hir_id)
366+
.or_default()
367+
.push(expected);
364368

365369
expected = self.try_structurally_resolve_type(pat.span, inner_ty);
366370
binding_mode = ByRef::Yes(match binding_mode {
@@ -382,13 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382386
max_ref_mutbl = MutblCap::Not;
383387
}
384388

385-
if !pat_adjustments.is_empty() {
386-
debug!("default binding mode is now {:?}", binding_mode);
387-
self.typeck_results
388-
.borrow_mut()
389-
.pat_adjustments_mut()
390-
.insert(pat.hir_id, pat_adjustments);
391-
}
389+
debug!("default binding mode is now {:?}", binding_mode);
392390

393391
(expected, binding_mode, max_ref_mutbl)
394392
}

0 commit comments

Comments
 (0)