@@ -7,7 +7,7 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
7
7
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
8
8
use rustc_middle:: {
9
9
hir:: place:: PlaceBase ,
10
- mir:: { self , BindingForm , ClearCrossCrate , Local , LocalDecl , LocalInfo , LocalKind , Location } ,
10
+ mir:: { self , BindingForm , Local , LocalDecl , LocalInfo , LocalKind , Location } ,
11
11
} ;
12
12
use rustc_span:: source_map:: DesugaringKind ;
13
13
use rustc_span:: symbol:: { kw, Symbol } ;
@@ -105,8 +105,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
105
105
reason = String :: new ( ) ;
106
106
} else {
107
107
item_msg = access_place_desc;
108
- let local_info = & self . body . local_decls [ local] . local_info ;
109
- if let Some ( box LocalInfo :: StaticRef { def_id, .. } ) = * local_info {
108
+ let local_info = self . body . local_decls [ local] . local_info ( ) ;
109
+ if let LocalInfo :: StaticRef { def_id, .. } = * local_info {
110
110
let static_name = & self . infcx . tcx . item_name ( def_id) ;
111
111
reason = format ! ( ", as `{static_name}` is an immutable static item" ) ;
112
112
} else {
@@ -305,15 +305,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
305
305
..
306
306
} ) = & self . body [ location. block ] . statements . get ( location. statement_index )
307
307
{
308
- match decl. local_info {
309
- Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: Var (
310
- mir:: VarBindingForm {
311
- binding_mode : ty:: BindingMode :: BindByValue ( Mutability :: Not ) ,
312
- opt_ty_info : Some ( sp) ,
313
- opt_match_place : _,
314
- pat_span : _,
315
- } ,
316
- ) ) ) ) => {
308
+ match * decl. local_info ( ) {
309
+ LocalInfo :: User ( BindingForm :: Var ( mir:: VarBindingForm {
310
+ binding_mode : ty:: BindingMode :: BindByValue ( Mutability :: Not ) ,
311
+ opt_ty_info : Some ( sp) ,
312
+ opt_match_place : _,
313
+ pat_span : _,
314
+ } ) ) => {
317
315
if suggest {
318
316
err. span_note ( sp, "the binding is already a mutable borrow" ) ;
319
317
}
@@ -346,10 +344,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
346
344
}
347
345
} else if decl. mutability . is_not ( ) {
348
346
if matches ! (
349
- decl. local_info,
350
- Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf (
351
- hir:: ImplicitSelfKind :: MutRef
352
- ) , ) ) )
347
+ decl. local_info( ) ,
348
+ LocalInfo :: User ( BindingForm :: ImplicitSelf ( hir:: ImplicitSelfKind :: MutRef ) )
353
349
) {
354
350
err. note (
355
351
"as `Self` may be unsized, this call attempts to take `&mut &mut self`" ,
@@ -482,22 +478,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
482
478
483
479
match self . local_names [ local] {
484
480
Some ( name) if !local_decl. from_compiler_desugaring ( ) => {
485
- let label = match local_decl. local_info . as_deref ( ) . unwrap ( ) {
486
- LocalInfo :: User ( ClearCrossCrate :: Set (
487
- mir:: BindingForm :: ImplicitSelf ( _) ,
488
- ) ) => {
481
+ let label = match * local_decl. local_info ( ) {
482
+ LocalInfo :: User ( mir:: BindingForm :: ImplicitSelf ( _) ) => {
489
483
let ( span, suggestion) =
490
484
suggest_ampmut_self ( self . infcx . tcx , local_decl) ;
491
485
Some ( ( true , span, suggestion) )
492
486
}
493
487
494
- LocalInfo :: User ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var (
495
- mir:: VarBindingForm {
496
- binding_mode : ty:: BindingMode :: BindByValue ( _) ,
497
- opt_ty_info,
498
- ..
499
- } ,
500
- ) ) ) => {
488
+ LocalInfo :: User ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
489
+ binding_mode : ty:: BindingMode :: BindByValue ( _) ,
490
+ opt_ty_info,
491
+ ..
492
+ } ) ) => {
501
493
// check if the RHS is from desugaring
502
494
let opt_assignment_rhs_span =
503
495
self . body . find_assignments ( local) . first ( ) . map ( |& location| {
@@ -534,16 +526,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
534
526
self . infcx . tcx ,
535
527
local_decl,
536
528
opt_assignment_rhs_span,
537
- * opt_ty_info,
529
+ opt_ty_info,
538
530
)
539
531
} else {
540
- match local_decl. local_info . as_deref ( ) {
541
- Some ( LocalInfo :: User ( ClearCrossCrate :: Set (
542
- mir:: BindingForm :: Var ( mir:: VarBindingForm {
543
- opt_ty_info : None ,
544
- ..
545
- } ) ,
546
- ) ) ) => {
532
+ match local_decl. local_info ( ) {
533
+ LocalInfo :: User ( mir:: BindingForm :: Var (
534
+ mir:: VarBindingForm {
535
+ opt_ty_info : None , ..
536
+ } ,
537
+ ) ) => {
547
538
let ( span, sugg) = suggest_ampmut_self (
548
539
self . infcx . tcx ,
549
540
local_decl,
@@ -555,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
555
546
self . infcx . tcx ,
556
547
local_decl,
557
548
opt_assignment_rhs_span,
558
- * opt_ty_info,
549
+ opt_ty_info,
559
550
) ,
560
551
}
561
552
} ;
@@ -564,21 +555,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
564
555
}
565
556
}
566
557
567
- LocalInfo :: User ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var (
568
- mir:: VarBindingForm {
569
- binding_mode : ty:: BindingMode :: BindByReference ( _) ,
570
- ..
571
- } ,
572
- ) ) ) => {
558
+ LocalInfo :: User ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
559
+ binding_mode : ty:: BindingMode :: BindByReference ( _) ,
560
+ ..
561
+ } ) ) => {
573
562
let pattern_span = local_decl. source_info . span ;
574
563
suggest_ref_mut ( self . infcx . tcx , pattern_span)
575
564
. map ( |replacement| ( true , pattern_span, replacement) )
576
565
}
577
566
578
- LocalInfo :: User ( ClearCrossCrate :: Clear ) => {
579
- bug ! ( "saw cleared local state" )
580
- }
581
-
582
567
_ => unreachable ! ( ) ,
583
568
} ;
584
569
@@ -1151,20 +1136,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
1151
1136
pub fn mut_borrow_of_mutable_ref ( local_decl : & LocalDecl < ' _ > , local_name : Option < Symbol > ) -> bool {
1152
1137
debug ! ( "local_info: {:?}, ty.kind(): {:?}" , local_decl. local_info, local_decl. ty. kind( ) ) ;
1153
1138
1154
- match local_decl. local_info . as_deref ( ) {
1139
+ match * local_decl. local_info ( ) {
1155
1140
// Check if mutably borrowing a mutable reference.
1156
- Some ( LocalInfo :: User ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var (
1157
- mir:: VarBindingForm {
1158
- binding_mode : ty:: BindingMode :: BindByValue ( Mutability :: Not ) , ..
1159
- } ,
1160
- ) ) ) ) => matches ! ( local_decl. ty. kind( ) , ty:: Ref ( _, _, hir:: Mutability :: Mut ) ) ,
1161
- Some ( LocalInfo :: User ( ClearCrossCrate :: Set ( mir:: BindingForm :: ImplicitSelf ( kind) ) ) ) => {
1141
+ LocalInfo :: User ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
1142
+ binding_mode : ty:: BindingMode :: BindByValue ( Mutability :: Not ) ,
1143
+ ..
1144
+ } ) ) => matches ! ( local_decl. ty. kind( ) , ty:: Ref ( _, _, hir:: Mutability :: Mut ) ) ,
1145
+ LocalInfo :: User ( mir:: BindingForm :: ImplicitSelf ( kind) ) => {
1162
1146
// Check if the user variable is a `&mut self` and we can therefore
1163
1147
// suggest removing the `&mut`.
1164
1148
//
1165
1149
// Deliberately fall into this case for all implicit self types,
1166
1150
// so that we don't fall in to the next case with them.
1167
- * kind == hir:: ImplicitSelfKind :: MutRef
1151
+ kind == hir:: ImplicitSelfKind :: MutRef
1168
1152
}
1169
1153
_ if Some ( kw:: SelfLower ) == local_name => {
1170
1154
// Otherwise, check if the name is the `self` keyword - in which case
0 commit comments