@@ -73,21 +73,23 @@ struct TopInfo<'tcx> {
73
73
/// found type `std::result::Result<_, _>`
74
74
/// ```
75
75
span : Option < Span > ,
76
+ /// The [`HirId`] of the top-level pattern.
77
+ hir_id : HirId ,
76
78
}
77
79
78
80
#[ derive( Copy , Clone ) ]
79
81
struct PatInfo < ' tcx , ' a > {
80
82
binding_mode : ByRef ,
81
83
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 > > ,
84
86
85
87
/// The depth of current pattern
86
88
current_depth : u32 ,
87
89
}
88
90
89
91
impl < ' 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 > {
91
93
let code = ObligationCauseCode :: Pattern {
92
94
span : ti. span ,
93
95
root_ty : ti. expected ,
@@ -101,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
101
103
cause_span : Span ,
102
104
expected : Ty < ' tcx > ,
103
105
actual : Ty < ' tcx > ,
104
- ti : TopInfo < ' tcx > ,
106
+ ti : & TopInfo < ' tcx > ,
105
107
) -> Option < Diag < ' tcx > > {
106
108
let mut diag =
107
109
self . demand_eqtype_with_origin ( & self . pattern_cause ( ti, cause_span) , expected, actual) ?;
@@ -118,7 +120,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
118
120
cause_span : Span ,
119
121
expected : Ty < ' tcx > ,
120
122
actual : Ty < ' tcx > ,
121
- ti : TopInfo < ' tcx > ,
123
+ ti : & TopInfo < ' tcx > ,
122
124
) {
123
125
if let Some ( err) = self . demand_eqtype_pat_diag ( cause_span, expected, actual, ti) {
124
126
err. emit ( ) ;
@@ -199,11 +201,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199
201
origin_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
200
202
decl_origin : Option < DeclOrigin < ' tcx > > ,
201
203
) {
202
- let info = TopInfo { expected, origin_expr, span } ;
204
+ let info = TopInfo { expected, origin_expr, span, hir_id : pat . hir_id } ;
203
205
let pat_info = PatInfo {
204
206
binding_mode : ByRef :: No ,
205
207
max_ref_mutbl : MutblCap :: Mut ,
206
- top_info : info,
208
+ top_info : & info,
207
209
decl_origin,
208
210
current_depth : 0 ,
209
211
} ;
@@ -463,7 +465,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
463
465
span : Span ,
464
466
lt : & hir:: Expr < ' tcx > ,
465
467
expected : Ty < ' tcx > ,
466
- ti : TopInfo < ' tcx > ,
468
+ ti : & TopInfo < ' tcx > ,
467
469
) -> Ty < ' tcx > {
468
470
// We've already computed the type above (when checking for a non-ref pat),
469
471
// so avoid computing it again.
@@ -533,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533
535
lhs : Option < & ' tcx hir:: Expr < ' tcx > > ,
534
536
rhs : Option < & ' tcx hir:: Expr < ' tcx > > ,
535
537
expected : Ty < ' tcx > ,
536
- ti : TopInfo < ' tcx > ,
538
+ ti : & TopInfo < ' tcx > ,
537
539
) -> Ty < ' tcx > {
538
540
let calc_side = |opt_expr : Option < & ' tcx hir:: Expr < ' tcx > > | match opt_expr {
539
541
None => None ,
@@ -671,18 +673,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
671
673
672
674
// Determine the binding mode...
673
675
let bm = match user_bind_annot {
676
+ // `mut` resets binding mode on edition <= 2021
674
677
BindingMode ( ByRef :: No , Mutability :: Mut )
675
678
if !( pat. span . at_least_rust_2024 ( )
676
679
&& self . tcx . features ( ) . mut_preserve_binding_mode_2024 )
677
680
&& matches ! ( def_br, ByRef :: Yes ( _) ) =>
678
681
{
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 ) ;
686
686
BindingMode ( ByRef :: No , Mutability :: Mut )
687
687
}
688
688
BindingMode ( ByRef :: No , mutbl) => BindingMode ( def_br, mutbl) ,
@@ -754,7 +754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
754
754
span : Span ,
755
755
var_id : HirId ,
756
756
ty : Ty < ' tcx > ,
757
- ti : TopInfo < ' tcx > ,
757
+ ti : & TopInfo < ' tcx > ,
758
758
) {
759
759
let var_ty = self . local_ty ( span, var_id) ;
760
760
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> {
996
996
qpath : & hir:: QPath < ' _ > ,
997
997
path_resolution : ( Res , Option < LoweredTy < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) ,
998
998
expected : Ty < ' tcx > ,
999
- ti : TopInfo < ' tcx > ,
999
+ ti : & TopInfo < ' tcx > ,
1000
1000
) -> Ty < ' tcx > {
1001
1001
let tcx = self . tcx ;
1002
1002
@@ -2178,8 +2178,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2178
2178
}
2179
2179
} else {
2180
2180
// 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 ;
2183
2192
}
2184
2193
2185
2194
let tcx = self . tcx ;
0 commit comments