@@ -137,7 +137,7 @@ enum AdjustMode {
137137 /// with mutability matching the pattern,
138138 /// mark the pattern as having consumed this reference.
139139 ///
140- /// `Span` is that of the inside of the reference pattern
140+ /// `Span` is that of the `&` or `&mut` itself
141141 ResetAndConsumeRef ( Mutability , Span ) ,
142142 /// Pass on the input binding mode and expected type.
143143 Pass ,
@@ -342,14 +342,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342342 match adjust_mode {
343343 AdjustMode :: Pass => ( expected, def_br, max_ref_mutbl, false ) ,
344344 AdjustMode :: Reset => ( expected, ByRef :: No , MutblCap :: Mut , false ) ,
345- AdjustMode :: ResetAndConsumeRef ( ref_pat_mutbl, inner_span ) => {
345+ AdjustMode :: ResetAndConsumeRef ( ref_pat_mutbl, ref_span ) => {
346346 // `&` pattern eats `&mut`
347347 let mutbls_match =
348348 if let ByRef :: Yes ( def_mut) = def_br { ref_pat_mutbl <= def_mut } else { false } ;
349349
350350 if pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 {
351351 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 ) )
353353 } else {
354354 max_ref_mutbl
355355 } ;
@@ -434,7 +434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
434434 // ```
435435 //
436436 // 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 ( ) ) ) ,
438438 // A `_` pattern works with any expected type, so there's no need to do anything.
439439 PatKind :: Wild
440440 // A malformed pattern doesn't have an expected type, so let's just accept any type.
0 commit comments