@@ -629,12 +629,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
629629 expected : Ty < ' tcx > ,
630630 pat_info : PatInfo < ' tcx , ' _ > ,
631631 ) -> Ty < ' tcx > {
632- let PatInfo { binding_mode : def_bm , top_info : ti, .. } = pat_info;
632+ let PatInfo { binding_mode : BindingAnnotation ( def_br , _ ) , top_info : ti, .. } = pat_info;
633633
634634 // Determine the binding mode...
635635 let bm = match ba {
636- BindingAnnotation ( ByRef :: No , Mutability :: Not ) => def_bm,
637- _ => ba,
636+ BindingAnnotation ( ByRef :: No , Mutability :: Mut )
637+ if !( pat. span . at_least_rust_2024 ( )
638+ && self . tcx . features ( ) . mut_dont_reset_binding_mode_2024 )
639+ && matches ! ( def_br, ByRef :: Yes ( _) ) =>
640+ {
641+ // `mut x` resets the binding mode in edition <= 2021.
642+ BindingAnnotation ( ByRef :: No , Mutability :: Mut )
643+ }
644+ BindingAnnotation ( ByRef :: No , mutbl) => BindingAnnotation ( def_br, mutbl) ,
645+ BindingAnnotation ( ByRef :: Yes ( _) , _) => ba,
638646 } ;
639647 // ...and store it in a side table:
640648 self . typeck_results . borrow_mut ( ) . pat_binding_modes_mut ( ) . insert ( pat. hir_id , bm) ;
@@ -743,7 +751,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
743751 }
744752 }
745753
746- // Precondition: pat is a Ref(_) pattern
754+ /// Precondition: pat is a ` Ref(_)` pattern
747755 fn borrow_pat_suggestion ( & self , err : & mut Diag < ' _ > , pat : & Pat < ' _ > ) {
748756 let tcx = self . tcx ;
749757 if let PatKind :: Ref ( inner, mutbl) = pat. kind
0 commit comments