1
- use borrow_check:: borrow_set:: { BorrowSet , BorrowData , TwoPhaseActivation } ;
1
+ use borrow_check:: borrow_set:: { BorrowData , BorrowSet , TwoPhaseActivation } ;
2
2
use borrow_check:: places_conflict;
3
- use borrow_check:: Context ;
4
3
use borrow_check:: AccessDepth ;
4
+ use borrow_check:: Context ;
5
5
use dataflow:: indexes:: BorrowIndex ;
6
6
use rustc:: mir:: { BasicBlock , Location , Mir , Place } ;
7
- use rustc:: mir:: { ProjectionElem , BorrowKind } ;
7
+ use rustc:: mir:: { BorrowKind , ProjectionElem } ;
8
+ use rustc:: mir:: { NeoPlace , PlaceBase } ;
8
9
use rustc:: ty:: TyCtxt ;
9
10
use rustc_data_structures:: graph:: dominators:: Dominators ;
10
11
@@ -13,11 +14,10 @@ use rustc_data_structures::graph::dominators::Dominators;
13
14
/// Activation phases.
14
15
pub ( super ) fn allow_two_phase_borrow < ' a , ' tcx , ' gcx : ' tcx > (
15
16
tcx : & TyCtxt < ' a , ' gcx , ' tcx > ,
16
- kind : BorrowKind
17
+ kind : BorrowKind ,
17
18
) -> bool {
18
19
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 )
21
21
}
22
22
23
23
/// Control for the path borrow checking code
@@ -28,7 +28,7 @@ pub(super) enum Control {
28
28
}
29
29
30
30
/// 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 > (
32
32
s : & mut S ,
33
33
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
34
34
mir : & Mir < ' tcx > ,
@@ -39,7 +39,7 @@ pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
39
39
mut op : F ,
40
40
) where
41
41
F : FnMut ( & mut S , BorrowIndex , & BorrowData < ' tcx > ) -> Control ,
42
- I : Iterator < Item = BorrowIndex >
42
+ I : Iterator < Item = BorrowIndex > ,
43
43
{
44
44
let ( access, place) = access_place;
45
45
@@ -75,9 +75,12 @@ pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
75
75
pub ( super ) fn is_active < ' tcx > (
76
76
dominators : & Dominators < BasicBlock > ,
77
77
borrow_data : & BorrowData < ' tcx > ,
78
- location : Location
78
+ location : Location ,
79
79
) -> bool {
80
- debug ! ( "is_active(borrow_data={:?}, location={:?})" , borrow_data, location) ;
80
+ debug ! (
81
+ "is_active(borrow_data={:?}, location={:?})" ,
82
+ borrow_data, location
83
+ ) ;
81
84
82
85
let activation_location = match borrow_data. activation_location {
83
86
// If this is not a 2-phase borrow, it is always active.
@@ -136,24 +139,28 @@ pub(super) fn is_active<'tcx>(
136
139
137
140
/// Determines if a given borrow is borrowing local data
138
141
/// 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
+ } ;
149
147
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 ;
156
155
}
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 ( ..) => { }
157
163
}
158
164
}
165
+ borrow_of_local_data
159
166
}
0 commit comments