@@ -61,7 +61,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
61
61
62
62
let mut err;
63
63
let item_msg;
64
- let diagnosing : PlaceAndReason < ' _ > ;
64
+ let diagnostic : PlaceAndReason < ' _ > ;
65
65
let mut opt_source = None ;
66
66
let access_place_desc = self . describe_any_place ( access_place. as_ref ( ) ) ;
67
67
debug ! ( "report_mutability_error: access_place_desc={:?}" , access_place_desc) ;
@@ -102,7 +102,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
102
102
return ;
103
103
} else {
104
104
item_msg = access_place_desc;
105
- diagnosing = if self . is_upvar_field_projection ( access_place. as_ref ( ) ) . is_some ( )
105
+ diagnostic = if self . is_upvar_field_projection ( access_place. as_ref ( ) ) . is_some ( )
106
106
{
107
107
PlaceAndReason :: DeclaredImmute ( item_msg. clone ( ) , None )
108
108
} else {
@@ -116,7 +116,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
116
116
if self . body . local_decls [ local] . is_ref_for_guard ( ) =>
117
117
{
118
118
item_msg = access_place_desc;
119
- diagnosing = PlaceAndReason :: InPatternGuard ( item_msg . clone ( ) )
119
+ diagnostic = PlaceAndReason :: InPatternGuard ( access_place_desc )
120
120
}
121
121
PlaceRef { local, projection : [ ProjectionElem :: Deref ] }
122
122
if self . body . local_decls [ local] . is_ref_to_static ( ) =>
@@ -145,7 +145,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
145
145
the_place_err. ty( self . body, self . infcx. tcx) . ty
146
146
) ) ;
147
147
148
- diagnosing = if self . is_upvar_field_projection ( access_place. as_ref ( ) ) . is_some ( )
148
+ diagnostic = if self . is_upvar_field_projection ( access_place. as_ref ( ) ) . is_some ( )
149
149
{
150
150
PlaceAndReason :: SelfCaptured ( item_msg. clone ( ) )
151
151
} else {
@@ -196,14 +196,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
196
196
let mut mut_error = None ;
197
197
let mut count = 1 ;
198
198
199
- let cant_access_here = |sp : Span | match error_access {
199
+ let access_diagnose_builder = |sp : Span | match error_access {
200
200
AccessKind :: MutableBorrow => FnMutBumpFn :: CannotBorrowMut { sp } ,
201
201
AccessKind :: Mutate => FnMutBumpFn :: CannotAssign { sp } ,
202
202
} ;
203
203
let span = match error_access {
204
- // cannot assign only happen in Mutate
205
204
AccessKind :: Mutate => {
206
- err = self . cannot_assign ( span, diagnosing ) ;
205
+ err = self . cannot_assign ( span, diagnostic ) ;
207
206
act = "assign" ;
208
207
acted_on = "written" ;
209
208
span
@@ -234,11 +233,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
234
233
suggest = false ;
235
234
} else {
236
235
err =
237
- self . cannot_borrow_path_as_mutable_because ( borrow_span, diagnosing ) ;
236
+ self . cannot_borrow_path_as_mutable_because ( borrow_span, diagnostic ) ;
238
237
}
239
238
}
240
239
_ => {
241
- err = self . cannot_borrow_path_as_mutable_because ( borrow_span, diagnosing ) ;
240
+ err = self . cannot_borrow_path_as_mutable_because ( borrow_span, diagnostic ) ;
242
241
}
243
242
}
244
243
if suggest {
@@ -278,7 +277,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
278
277
ProjectionElem :: Deref ,
279
278
] ,
280
279
} => {
281
- err. subdiagnostic ( cant_access_here ( span) ) ;
280
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
282
281
283
282
let place = Place :: ty_from ( local, proj_base, self . body , self . infcx . tcx ) ;
284
283
if let Some ( span) = get_mut_span_in_struct_field ( self . infcx . tcx , place. ty , * field) {
@@ -300,7 +299,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
300
299
. is_some_and ( |l| mut_borrow_of_mutable_ref ( l, self . local_names [ local] ) ) =>
301
300
{
302
301
let decl = & self . body . local_decls [ local] ;
303
- err. subdiagnostic ( cant_access_here ( span) ) ;
302
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
304
303
if let Some ( mir:: Statement {
305
304
source_info,
306
305
kind :
@@ -385,7 +384,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
385
384
assert_eq ! ( local_decl. mutability, Mutability :: Not ) ;
386
385
387
386
if count < 10 {
388
- err. subdiagnostic ( cant_access_here ( span) ) ;
387
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
389
388
}
390
389
if suggest {
391
390
self . construct_mut_suggestion_for_local_binding_patterns ( & mut err, local) ;
@@ -407,7 +406,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
407
406
408
407
let captured_place = & self . upvars [ upvar_index. index ( ) ] . place ;
409
408
410
- err. subdiagnostic ( cant_access_here ( span) ) ;
409
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
411
410
412
411
let upvar_hir_id = captured_place. get_root_variable ( ) ;
413
412
@@ -462,7 +461,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
462
461
. span_to_snippet ( span)
463
462
. is_ok_and ( |snippet| snippet. starts_with ( "&mut " ) ) =>
464
463
{
465
- err. subdiagnostic ( cant_access_here ( span) ) ;
464
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
466
465
err. span_suggestion (
467
466
span,
468
467
"try removing `&mut` here" ,
@@ -474,7 +473,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
474
473
PlaceRef { local, projection : [ ProjectionElem :: Deref ] }
475
474
if self . body . local_decls [ local] . is_ref_for_guard ( ) =>
476
475
{
477
- err. subdiagnostic ( cant_access_here ( span) ) ;
476
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
478
477
err. note (
479
478
"variables bound in patterns are immutable until the end of the pattern guard" ,
480
479
) ;
@@ -518,12 +517,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
518
517
PlaceRef { local, projection : [ ProjectionElem :: Deref ] }
519
518
if local == ty:: CAPTURE_STRUCT_LOCAL && !self . upvars . is_empty ( ) =>
520
519
{
521
- err. subdiagnostic ( cant_access_here ( span) ) ;
520
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
522
521
self . expected_fn_found_fn_mut_call ( & mut err) ;
523
522
}
524
523
525
524
PlaceRef { local : _, projection : [ .., ProjectionElem :: Deref ] } => {
526
- err. subdiagnostic ( cant_access_here ( span) ) ;
525
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
527
526
528
527
match opt_source {
529
528
Some ( BorrowedContentSource :: OverloadedDeref ( ty) ) => {
@@ -544,7 +543,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
544
543
}
545
544
546
545
_ => {
547
- err. subdiagnostic ( cant_access_here ( span) ) ;
546
+ err. subdiagnostic ( access_diagnose_builder ( span) ) ;
548
547
}
549
548
}
550
549
0 commit comments