@@ -139,7 +139,7 @@ enum AdjustMode {
139
139
/// with mutability matching the pattern,
140
140
/// mark the pattern as having consumed this reference.
141
141
///
142
- /// `Span` is that of the inside of the reference pattern
142
+ /// `Span` is that of the `&` or `&mut` itself
143
143
ResetAndConsumeRef ( Mutability , Span ) ,
144
144
/// Pass on the input binding mode and expected type.
145
145
Pass ,
@@ -344,14 +344,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
344
344
match adjust_mode {
345
345
AdjustMode :: Pass => ( expected, def_br, max_ref_mutbl, false ) ,
346
346
AdjustMode :: Reset => ( expected, ByRef :: No , MutblCap :: Mut , false ) ,
347
- AdjustMode :: ResetAndConsumeRef ( ref_pat_mutbl, inner_span ) => {
347
+ AdjustMode :: ResetAndConsumeRef ( ref_pat_mutbl, ref_span ) => {
348
348
// `&` pattern eats `&mut`
349
349
let mutbls_match =
350
350
if let ByRef :: Yes ( def_mut) = def_br { ref_pat_mutbl <= def_mut } else { false } ;
351
351
352
352
if pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 {
353
353
let max_ref_mutbl = if ref_pat_mutbl == Mutability :: Not {
354
- max_ref_mutbl. cap_mutbl_to_not ( Some ( pat . span . until ( inner_span ) ) )
354
+ max_ref_mutbl. cap_mutbl_to_not ( Some ( ref_span ) )
355
355
} else {
356
356
max_ref_mutbl
357
357
} ;
@@ -436,7 +436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
436
436
// ```
437
437
//
438
438
// See issue #46688.
439
- PatKind :: Ref ( inner, mutbl) => AdjustMode :: ResetAndConsumeRef ( * mutbl, inner. span ) ,
439
+ PatKind :: Ref ( inner, mutbl) => AdjustMode :: ResetAndConsumeRef ( * mutbl, pat . span . until ( inner. span . find_ancestor_inside ( pat . span ) . unwrap ( ) ) ) ,
440
440
// A `_` pattern works with any expected type, so there's no need to do anything.
441
441
PatKind :: Wild
442
442
// A malformed pattern doesn't have an expected type, so let's just accept any type.
0 commit comments