@@ -492,7 +492,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
492492 // Special-case reborrows to be more like a copy of a reference.
493493 match * rvalue {
494494 Rvalue :: Ref ( _, kind, place) => {
495- if let Some ( reborrowed_proj ) = place_as_reborrow ( self . tcx , self . body , place) {
495+ if let Some ( place_ref ) = place_as_reborrow ( self . tcx , self . body , place) {
496496 let ctx = match kind {
497497 BorrowKind :: Shared => {
498498 PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
@@ -508,20 +508,20 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
508508 }
509509 } ;
510510 self . visit_local ( & place. local , ctx, location) ;
511- self . visit_projection ( place. local , reborrowed_proj , ctx, location) ;
511+ self . visit_projection ( place. local , place_ref . projection , ctx, location) ;
512512 return ;
513513 }
514514 }
515515 Rvalue :: AddressOf ( mutbl, place) => {
516- if let Some ( reborrowed_proj ) = place_as_reborrow ( self . tcx , self . body , place) {
516+ if let Some ( place_ref ) = place_as_reborrow ( self . tcx , self . body , place) {
517517 let ctx = match mutbl {
518518 Mutability :: Not => {
519519 PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: AddressOf )
520520 }
521521 Mutability :: Mut => PlaceContext :: MutatingUse ( MutatingUseContext :: AddressOf ) ,
522522 } ;
523523 self . visit_local ( & place. local , ctx, location) ;
524- self . visit_projection ( place. local , reborrowed_proj , ctx, location) ;
524+ self . visit_projection ( place. local , place_ref . projection , ctx, location) ;
525525 return ;
526526 }
527527 }
@@ -1016,7 +1016,7 @@ fn place_as_reborrow(
10161016 tcx : TyCtxt < ' tcx > ,
10171017 body : & Body < ' tcx > ,
10181018 place : Place < ' tcx > ,
1019- ) -> Option < & ' a [ PlaceElem < ' tcx > ] > {
1019+ ) -> Option < PlaceRef < ' tcx > > {
10201020 match place. as_ref ( ) . last_projection ( ) {
10211021 Some ( ( place_base, ProjectionElem :: Deref ) ) => {
10221022 // A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
@@ -1025,13 +1025,14 @@ fn place_as_reborrow(
10251025 None
10261026 } else {
10271027 // Ensure the type being derefed is a reference and not a raw pointer.
1028- //
10291028 // This is sufficient to prevent an access to a `static mut` from being marked as a
10301029 // reborrow, even if the check above were to disappear.
10311030 let inner_ty = place_base. ty ( body, tcx) . ty ;
1032- match inner_ty. kind ( ) {
1033- ty:: Ref ( ..) => Some ( place_base. projection ) ,
1034- _ => None ,
1031+
1032+ if let ty:: Ref ( ..) = inner_ty. kind ( ) {
1033+ return Some ( place_base) ;
1034+ } else {
1035+ return None ;
10351036 }
10361037 }
10371038 }
0 commit comments