@@ -7,7 +7,7 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
77use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
88use rustc_middle:: {
99 hir:: place:: PlaceBase ,
10- mir:: { self , BindingForm , ClearCrossCrate , Local , LocalDecl , LocalInfo , LocalKind , Location } ,
10+ mir:: { self , BindingForm , Local , LocalDecl , LocalInfo , LocalKind , Location } ,
1111} ;
1212use rustc_span:: source_map:: DesugaringKind ;
1313use rustc_span:: symbol:: { kw, Symbol } ;
@@ -105,8 +105,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
105105 reason = String :: new ( ) ;
106106 } else {
107107 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 {
110110 let static_name = & self . infcx . tcx . item_name ( def_id) ;
111111 reason = format ! ( ", as `{static_name}` is an immutable static item" ) ;
112112 } else {
@@ -305,15 +305,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
305305 ..
306306 } ) = & self . body [ location. block ] . statements . get ( location. statement_index )
307307 {
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+ } ) ) => {
317315 if suggest {
318316 err. span_note ( sp, "the binding is already a mutable borrow" ) ;
319317 }
@@ -346,10 +344,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
346344 }
347345 } else if decl. mutability . is_not ( ) {
348346 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 ) )
353349 ) {
354350 err. note (
355351 "as `Self` may be unsized, this call attempts to take `&mut &mut self`" ,
@@ -482,22 +478,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
482478
483479 match self . local_names [ local] {
484480 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 ( _) ) => {
489483 let ( span, suggestion) =
490484 suggest_ampmut_self ( self . infcx . tcx , local_decl) ;
491485 Some ( ( true , span, suggestion) )
492486 }
493487
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+ } ) ) => {
501493 // check if the RHS is from desugaring
502494 let opt_assignment_rhs_span =
503495 self . body . find_assignments ( local) . first ( ) . map ( |& location| {
@@ -534,16 +526,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
534526 self . infcx . tcx ,
535527 local_decl,
536528 opt_assignment_rhs_span,
537- * opt_ty_info,
529+ opt_ty_info,
538530 )
539531 } 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+ ) ) => {
547538 let ( span, sugg) = suggest_ampmut_self (
548539 self . infcx . tcx ,
549540 local_decl,
@@ -555,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
555546 self . infcx . tcx ,
556547 local_decl,
557548 opt_assignment_rhs_span,
558- * opt_ty_info,
549+ opt_ty_info,
559550 ) ,
560551 }
561552 } ;
@@ -564,21 +555,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
564555 }
565556 }
566557
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+ } ) ) => {
573562 let pattern_span = local_decl. source_info . span ;
574563 suggest_ref_mut ( self . infcx . tcx , pattern_span)
575564 . map ( |replacement| ( true , pattern_span, replacement) )
576565 }
577566
578- LocalInfo :: User ( ClearCrossCrate :: Clear ) => {
579- bug ! ( "saw cleared local state" )
580- }
581-
582567 _ => unreachable ! ( ) ,
583568 } ;
584569
@@ -1151,20 +1136,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11511136pub fn mut_borrow_of_mutable_ref ( local_decl : & LocalDecl < ' _ > , local_name : Option < Symbol > ) -> bool {
11521137 debug ! ( "local_info: {:?}, ty.kind(): {:?}" , local_decl. local_info, local_decl. ty. kind( ) ) ;
11531138
1154- match local_decl. local_info . as_deref ( ) {
1139+ match * local_decl. local_info ( ) {
11551140 // 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) ) => {
11621146 // Check if the user variable is a `&mut self` and we can therefore
11631147 // suggest removing the `&mut`.
11641148 //
11651149 // Deliberately fall into this case for all implicit self types,
11661150 // so that we don't fall in to the next case with them.
1167- * kind == hir:: ImplicitSelfKind :: MutRef
1151+ kind == hir:: ImplicitSelfKind :: MutRef
11681152 }
11691153 _ if Some ( kw:: SelfLower ) == local_name => {
11701154 // Otherwise, check if the name is the `self` keyword - in which case
0 commit comments