@@ -629,12 +629,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
629
629
expected : Ty < ' tcx > ,
630
630
pat_info : PatInfo < ' tcx , ' _ > ,
631
631
) -> 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;
633
633
634
634
// Determine the binding mode...
635
635
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,
638
646
} ;
639
647
// ...and store it in a side table:
640
648
self . typeck_results . borrow_mut ( ) . pat_binding_modes_mut ( ) . insert ( pat. hir_id , bm) ;
@@ -743,7 +751,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
743
751
}
744
752
}
745
753
746
- // Precondition: pat is a Ref(_) pattern
754
+ /// Precondition: pat is a ` Ref(_)` pattern
747
755
fn borrow_pat_suggestion ( & self , err : & mut Diag < ' _ > , pat : & Pat < ' _ > ) {
748
756
let tcx = self . tcx ;
749
757
if let PatKind :: Ref ( inner, mutbl) = pat. kind
0 commit comments