@@ -492,7 +492,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
492
492
// Special-case reborrows to be more like a copy of a reference.
493
493
match * rvalue {
494
494
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) {
496
496
let ctx = match kind {
497
497
BorrowKind :: Shared => {
498
498
PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
@@ -508,20 +508,20 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
508
508
}
509
509
} ;
510
510
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) ;
512
512
return ;
513
513
}
514
514
}
515
515
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) {
517
517
let ctx = match mutbl {
518
518
Mutability :: Not => {
519
519
PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: AddressOf )
520
520
}
521
521
Mutability :: Mut => PlaceContext :: MutatingUse ( MutatingUseContext :: AddressOf ) ,
522
522
} ;
523
523
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) ;
525
525
return ;
526
526
}
527
527
}
@@ -1016,7 +1016,7 @@ fn place_as_reborrow(
1016
1016
tcx : TyCtxt < ' tcx > ,
1017
1017
body : & Body < ' tcx > ,
1018
1018
place : Place < ' tcx > ,
1019
- ) -> Option < & ' a [ PlaceElem < ' tcx > ] > {
1019
+ ) -> Option < PlaceRef < ' tcx > > {
1020
1020
match place. as_ref ( ) . last_projection ( ) {
1021
1021
Some ( ( place_base, ProjectionElem :: Deref ) ) => {
1022
1022
// 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(
1025
1025
None
1026
1026
} else {
1027
1027
// Ensure the type being derefed is a reference and not a raw pointer.
1028
- //
1029
1028
// This is sufficient to prevent an access to a `static mut` from being marked as a
1030
1029
// reborrow, even if the check above were to disappear.
1031
1030
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 ;
1035
1036
}
1036
1037
}
1037
1038
}
0 commit comments