@@ -16,7 +16,7 @@ use rustc::mir::traversal;
16
16
use rustc:: mir:: visit:: {
17
17
PlaceContext , Visitor , NonUseContext , MutatingUseContext , NonMutatingUseContext
18
18
} ;
19
- use rustc:: mir:: { self , Location , Mir , Place , Local } ;
19
+ use rustc:: mir:: { self , Location , Mir , Local } ;
20
20
use rustc:: ty:: { RegionVid , TyCtxt } ;
21
21
use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
22
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
@@ -41,10 +41,6 @@ crate struct BorrowSet<'tcx> {
41
41
/// only need to store one borrow index
42
42
crate activation_map : FxHashMap < Location , Vec < BorrowIndex > > ,
43
43
44
- /// Every borrow has a region; this maps each such regions back to
45
- /// its borrow-indexes.
46
- crate region_map : FxHashMap < RegionVid , FxHashSet < BorrowIndex > > ,
47
-
48
44
/// Map from local to all the borrows on that local
49
45
crate local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
50
46
@@ -149,7 +145,6 @@ impl<'tcx> BorrowSet<'tcx> {
149
145
idx_vec : IndexVec :: new ( ) ,
150
146
location_map : Default :: default ( ) ,
151
147
activation_map : Default :: default ( ) ,
152
- region_map : Default :: default ( ) ,
153
148
local_map : Default :: default ( ) ,
154
149
pending_activations : Default :: default ( ) ,
155
150
locals_state_at_exit :
@@ -164,7 +159,6 @@ impl<'tcx> BorrowSet<'tcx> {
164
159
borrows : visitor. idx_vec ,
165
160
location_map : visitor. location_map ,
166
161
activation_map : visitor. activation_map ,
167
- region_map : visitor. region_map ,
168
162
local_map : visitor. local_map ,
169
163
locals_state_at_exit : visitor. locals_state_at_exit ,
170
164
}
@@ -184,7 +178,6 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
184
178
idx_vec : IndexVec < BorrowIndex , BorrowData < ' tcx > > ,
185
179
location_map : FxHashMap < Location , BorrowIndex > ,
186
180
activation_map : FxHashMap < Location , Vec < BorrowIndex > > ,
187
- region_map : FxHashMap < RegionVid , FxHashSet < BorrowIndex > > ,
188
181
local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
189
182
190
183
/// When we encounter a 2-phase borrow statement, it will always
@@ -229,7 +222,6 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
229
222
230
223
self . insert_as_pending_if_two_phase ( location, & assigned_place, kind, idx) ;
231
224
232
- self . region_map . entry ( region) . or_default ( ) . insert ( idx) ;
233
225
if let Some ( local) = borrowed_place. root_local ( ) {
234
226
self . local_map . entry ( local) . or_default ( ) . insert ( idx) ;
235
227
}
@@ -238,68 +230,68 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
238
230
self . super_assign ( block, assigned_place, rvalue, location)
239
231
}
240
232
241
- fn visit_place (
233
+ fn visit_local (
242
234
& mut self ,
243
- place : & mir :: Place < ' tcx > ,
235
+ temp : & Local ,
244
236
context : PlaceContext < ' tcx > ,
245
237
location : Location ,
246
238
) {
247
- self . super_place ( place, context, location) ;
248
-
249
- // We found a use of some temporary TEMP...
250
- if let Place :: Local ( temp) = place {
251
- // ... check whether we (earlier) saw a 2-phase borrow like
252
- //
253
- // TMP = &mut place
254
- if let Some ( & borrow_index) = self . pending_activations . get ( temp) {
255
- let borrow_data = & mut self . idx_vec [ borrow_index] ;
256
-
257
- // Watch out: the use of TMP in the borrow itself
258
- // doesn't count as an activation. =)
259
- if borrow_data. reserve_location == location &&
260
- context == PlaceContext :: MutatingUse ( MutatingUseContext :: Store )
261
- {
262
- return ;
263
- }
239
+ if !context. is_use ( ) {
240
+ return ;
241
+ }
264
242
265
- if let TwoPhaseActivation :: ActivatedAt ( other_location) =
266
- borrow_data. activation_location {
267
- span_bug ! (
268
- self . mir. source_info( location) . span,
269
- "found two uses for 2-phase borrow temporary {:?}: \
270
- {:?} and {:?}",
271
- temp,
272
- location,
273
- other_location,
274
- ) ;
275
- }
243
+ // We found a use of some temporary TMP
244
+ // check whether we (earlier) saw a 2-phase borrow like
245
+ //
246
+ // TMP = &mut place
247
+ if let Some ( & borrow_index) = self . pending_activations . get ( temp) {
248
+ let borrow_data = & mut self . idx_vec [ borrow_index] ;
276
249
277
- // Otherwise, this is the unique later use
278
- // that we expect.
279
- borrow_data. activation_location = match context {
280
- // The use of TMP in a shared borrow does not
281
- // count as an actual activation.
282
- PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow ( ..) ) |
283
- PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: ShallowBorrow ( ..) ) =>
284
- TwoPhaseActivation :: NotActivated ,
285
- _ => {
286
- // Double check: This borrow is indeed a two-phase borrow (that is,
287
- // we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
288
- // we've not found any other activations (checked above).
289
- assert_eq ! (
290
- borrow_data. activation_location,
291
- TwoPhaseActivation :: NotActivated ,
292
- "never found an activation for this borrow!" ,
293
- ) ;
294
-
295
- self . activation_map
296
- . entry ( location)
297
- . or_default ( )
298
- . push ( borrow_index) ;
299
- TwoPhaseActivation :: ActivatedAt ( location)
300
- }
301
- } ;
250
+ // Watch out: the use of TMP in the borrow itself
251
+ // doesn't count as an activation. =)
252
+ if borrow_data. reserve_location == location &&
253
+ context == PlaceContext :: MutatingUse ( MutatingUseContext :: Store )
254
+ {
255
+ return ;
256
+ }
257
+
258
+ if let TwoPhaseActivation :: ActivatedAt ( other_location) =
259
+ borrow_data. activation_location {
260
+ span_bug ! (
261
+ self . mir. source_info( location) . span,
262
+ "found two uses for 2-phase borrow temporary {:?}: \
263
+ {:?} and {:?}",
264
+ temp,
265
+ location,
266
+ other_location,
267
+ ) ;
302
268
}
269
+
270
+ // Otherwise, this is the unique later use
271
+ // that we expect.
272
+ borrow_data. activation_location = match context {
273
+ // The use of TMP in a shared borrow does not
274
+ // count as an actual activation.
275
+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow ( ..) ) |
276
+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: ShallowBorrow ( ..) ) =>
277
+ TwoPhaseActivation :: NotActivated ,
278
+ _ => {
279
+ // Double check: This borrow is indeed a two-phase borrow (that is,
280
+ // we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
281
+ // we've not found any other activations (checked above).
282
+ assert_eq ! (
283
+ borrow_data. activation_location,
284
+ TwoPhaseActivation :: NotActivated ,
285
+ "never found an activation for this borrow!" ,
286
+ ) ;
287
+
288
+ self . activation_map
289
+ . entry ( location)
290
+ . or_default ( )
291
+ . push ( borrow_index) ;
292
+ TwoPhaseActivation :: ActivatedAt ( location)
293
+ }
294
+ } ;
303
295
}
304
296
}
305
297
0 commit comments