@@ -73,21 +73,23 @@ struct TopInfo<'tcx> {
7373 /// found type `std::result::Result<_, _>`
7474 /// ```
7575 span : Option < Span > ,
76+ /// The [`HirId`] of the top-level pattern.
77+ hir_id : HirId ,
7678}
7779
7880#[ derive( Copy , Clone ) ]
7981struct PatInfo < ' tcx , ' a > {
8082 binding_mode : ByRef ,
8183 max_ref_mutbl : MutblCap ,
82- top_info : TopInfo < ' tcx > ,
83- decl_origin : Option < DeclOrigin < ' a > > ,
84+ top_info : & ' a TopInfo < ' tcx > ,
85+ decl_origin : Option < DeclOrigin < ' tcx > > ,
8486
8587 /// The depth of current pattern
8688 current_depth : u32 ,
8789}
8890
8991impl < ' tcx > FnCtxt < ' _ , ' tcx > {
90- fn pattern_cause ( & self , ti : TopInfo < ' tcx > , cause_span : Span ) -> ObligationCause < ' tcx > {
92+ fn pattern_cause ( & self , ti : & TopInfo < ' tcx > , cause_span : Span ) -> ObligationCause < ' tcx > {
9193 let code = ObligationCauseCode :: Pattern {
9294 span : ti. span ,
9395 root_ty : ti. expected ,
@@ -101,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
101103 cause_span : Span ,
102104 expected : Ty < ' tcx > ,
103105 actual : Ty < ' tcx > ,
104- ti : TopInfo < ' tcx > ,
106+ ti : & TopInfo < ' tcx > ,
105107 ) -> Option < Diag < ' tcx > > {
106108 let mut diag =
107109 self . demand_eqtype_with_origin ( & self . pattern_cause ( ti, cause_span) , expected, actual) ?;
@@ -118,7 +120,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
118120 cause_span : Span ,
119121 expected : Ty < ' tcx > ,
120122 actual : Ty < ' tcx > ,
121- ti : TopInfo < ' tcx > ,
123+ ti : & TopInfo < ' tcx > ,
122124 ) {
123125 if let Some ( err) = self . demand_eqtype_pat_diag ( cause_span, expected, actual, ti) {
124126 err. emit ( ) ;
@@ -199,11 +201,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199201 origin_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
200202 decl_origin : Option < DeclOrigin < ' tcx > > ,
201203 ) {
202- let info = TopInfo { expected, origin_expr, span } ;
204+ let info = TopInfo { expected, origin_expr, span, hir_id : pat . hir_id } ;
203205 let pat_info = PatInfo {
204206 binding_mode : ByRef :: No ,
205207 max_ref_mutbl : MutblCap :: Mut ,
206- top_info : info,
208+ top_info : & info,
207209 decl_origin,
208210 current_depth : 0 ,
209211 } ;
@@ -463,7 +465,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
463465 span : Span ,
464466 lt : & hir:: Expr < ' tcx > ,
465467 expected : Ty < ' tcx > ,
466- ti : TopInfo < ' tcx > ,
468+ ti : & TopInfo < ' tcx > ,
467469 ) -> Ty < ' tcx > {
468470 // We've already computed the type above (when checking for a non-ref pat),
469471 // so avoid computing it again.
@@ -533,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533535 lhs : Option < & ' tcx hir:: Expr < ' tcx > > ,
534536 rhs : Option < & ' tcx hir:: Expr < ' tcx > > ,
535537 expected : Ty < ' tcx > ,
536- ti : TopInfo < ' tcx > ,
538+ ti : & TopInfo < ' tcx > ,
537539 ) -> Ty < ' tcx > {
538540 let calc_side = |opt_expr : Option < & ' tcx hir:: Expr < ' tcx > > | match opt_expr {
539541 None => None ,
@@ -671,18 +673,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
671673
672674 // Determine the binding mode...
673675 let bm = match user_bind_annot {
676+ // `mut` resets binding mode on edition <= 2021
674677 BindingMode ( ByRef :: No , Mutability :: Mut )
675678 if !( pat. span . at_least_rust_2024 ( )
676679 && self . tcx . features ( ) . mut_preserve_binding_mode_2024 )
677680 && matches ! ( def_br, ByRef :: Yes ( _) ) =>
678681 {
679- // `mut x` resets the binding mode in edition <= 2021.
680- self . tcx . emit_node_span_lint (
681- rustc_lint:: builtin:: DEREFERENCING_MUT_BINDING ,
682- pat. hir_id ,
683- pat. span ,
684- errors:: DereferencingMutBinding { span : pat. span } ,
685- ) ;
682+ self . typeck_results
683+ . borrow_mut ( )
684+ . rust_2024_migration_desugared_pats_mut ( )
685+ . insert ( pat_info. top_info . hir_id ) ;
686686 BindingMode ( ByRef :: No , Mutability :: Mut )
687687 }
688688 BindingMode ( ByRef :: No , mutbl) => BindingMode ( def_br, mutbl) ,
@@ -754,7 +754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
754754 span : Span ,
755755 var_id : HirId ,
756756 ty : Ty < ' tcx > ,
757- ti : TopInfo < ' tcx > ,
757+ ti : & TopInfo < ' tcx > ,
758758 ) {
759759 let var_ty = self . local_ty ( span, var_id) ;
760760 if let Some ( mut err) = self . demand_eqtype_pat_diag ( span, var_ty, ty, ti) {
@@ -996,7 +996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
996996 qpath : & hir:: QPath < ' _ > ,
997997 path_resolution : ( Res , Option < LoweredTy < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) ,
998998 expected : Ty < ' tcx > ,
999- ti : TopInfo < ' tcx > ,
999+ ti : & TopInfo < ' tcx > ,
10001000 ) -> Ty < ' tcx > {
10011001 let tcx = self . tcx ;
10021002
@@ -2178,8 +2178,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21782178 }
21792179 } else {
21802180 // Reset binding mode on old editions
2181- pat_info. binding_mode = ByRef :: No ;
2182- pat_info. max_ref_mutbl = MutblCap :: Mut
2181+
2182+ if pat_info. binding_mode != ByRef :: No {
2183+ pat_info. binding_mode = ByRef :: No ;
2184+
2185+ self . typeck_results
2186+ . borrow_mut ( )
2187+ . rust_2024_migration_desugared_pats_mut ( )
2188+ . insert ( pat_info. top_info . hir_id ) ;
2189+ }
2190+
2191+ pat_info. max_ref_mutbl = MutblCap :: Mut ;
21832192 }
21842193
21852194 let tcx = self . tcx ;
0 commit comments