1- use borrow_check:: borrow_set:: { BorrowSet , BorrowData , TwoPhaseActivation } ;
1+ use borrow_check:: borrow_set:: { BorrowData , BorrowSet , TwoPhaseActivation } ;
22use borrow_check:: places_conflict;
3- use borrow_check:: Context ;
43use borrow_check:: AccessDepth ;
4+ use borrow_check:: Context ;
55use dataflow:: indexes:: BorrowIndex ;
66use rustc:: mir:: { BasicBlock , Location , Mir , Place } ;
7- use rustc:: mir:: { ProjectionElem , BorrowKind } ;
7+ use rustc:: mir:: { BorrowKind , ProjectionElem } ;
8+ use rustc:: mir:: { NeoPlace , PlaceBase } ;
89use rustc:: ty:: TyCtxt ;
910use rustc_data_structures:: graph:: dominators:: Dominators ;
1011
@@ -13,11 +14,10 @@ use rustc_data_structures::graph::dominators::Dominators;
1314/// Activation phases.
1415pub ( super ) fn allow_two_phase_borrow < ' a , ' tcx , ' gcx : ' tcx > (
1516 tcx : & TyCtxt < ' a , ' gcx , ' tcx > ,
16- kind : BorrowKind
17+ kind : BorrowKind ,
1718) -> bool {
1819 tcx. two_phase_borrows ( )
19- && ( kind. allows_two_phase_borrow ( )
20- || tcx. sess . opts . debugging_opts . two_phase_beyond_autoref )
20+ && ( kind. allows_two_phase_borrow ( ) || tcx. sess . opts . debugging_opts . two_phase_beyond_autoref )
2121}
2222
2323/// Control for the path borrow checking code
@@ -28,7 +28,7 @@ pub(super) enum Control {
2828}
2929
3030/// Encapsulates the idea of iterating over every borrow that involves a particular path
31- pub ( super ) fn each_borrow_involving_path < ' a , ' tcx , ' gcx : ' tcx , F , I , S > (
31+ pub ( super ) fn each_borrow_involving_path < ' a , ' tcx , ' gcx : ' tcx , F , I , S > (
3232 s : & mut S ,
3333 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
3434 mir : & Mir < ' tcx > ,
@@ -39,7 +39,7 @@ pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
3939 mut op : F ,
4040) where
4141 F : FnMut ( & mut S , BorrowIndex , & BorrowData < ' tcx > ) -> Control ,
42- I : Iterator < Item = BorrowIndex >
42+ I : Iterator < Item = BorrowIndex > ,
4343{
4444 let ( access, place) = access_place;
4545
@@ -75,9 +75,12 @@ pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
7575pub ( super ) fn is_active < ' tcx > (
7676 dominators : & Dominators < BasicBlock > ,
7777 borrow_data : & BorrowData < ' tcx > ,
78- location : Location
78+ location : Location ,
7979) -> bool {
80- debug ! ( "is_active(borrow_data={:?}, location={:?})" , borrow_data, location) ;
80+ debug ! (
81+ "is_active(borrow_data={:?}, location={:?})" ,
82+ borrow_data, location
83+ ) ;
8184
8285 let activation_location = match borrow_data. activation_location {
8386 // If this is not a 2-phase borrow, it is always active.
@@ -136,24 +139,28 @@ pub(super) fn is_active<'tcx>(
136139
137140/// Determines if a given borrow is borrowing local data
138141/// This is called for all Yield statements on movable generators
139- pub ( super ) fn borrow_of_local_data < ' tcx > ( place : & Place < ' tcx > ) -> bool {
140- match place {
141- Place :: Promoted ( _) |
142- Place :: Static ( ..) => false ,
143- Place :: Local ( ..) => true ,
144- Place :: Projection ( box proj) => {
145- match proj. elem {
146- // Reborrow of already borrowed data is ignored
147- // Any errors will be caught on the initial borrow
148- ProjectionElem :: Deref => false ,
142+ pub ( super ) fn borrow_of_local_data < ' tcx > ( place : & NeoPlace < ' tcx > ) -> bool {
143+ let mut borrow_of_local_data = match place. base {
144+ PlaceBase :: Promoted ( _) | PlaceBase :: Static ( ..) => false ,
145+ PlaceBase :: Local ( ..) => true ,
146+ } ;
149147
150- // For interior references and downcasts, find out if the base is local
151- ProjectionElem :: Field ( ..)
152- | ProjectionElem :: Index ( ..)
153- | ProjectionElem :: ConstantIndex { .. }
154- | ProjectionElem :: Subslice { .. }
155- | ProjectionElem :: Downcast ( ..) => borrow_of_local_data ( & proj. base ) ,
148+ for elem in place. elems . iter ( ) . rev ( ) {
149+ match elem {
150+ // Reborrow of already borrowed data is ignored
151+ // Any errors will be caught on the initial borrow
152+ ProjectionElem :: Deref => {
153+ borrow_of_local_data = false ;
154+ break ;
156155 }
156+
157+ // For interior references and downcasts, find out if the base is local
158+ ProjectionElem :: Field ( ..)
159+ | ProjectionElem :: Index ( ..)
160+ | ProjectionElem :: ConstantIndex { .. }
161+ | ProjectionElem :: Subslice { .. }
162+ | ProjectionElem :: Downcast ( ..) => { }
157163 }
158164 }
165+ borrow_of_local_data
159166}
0 commit comments