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