@@ -16,7 +16,7 @@ use rustc::mir::traversal;
1616use rustc:: mir:: visit:: {
1717 PlaceContext , Visitor , NonUseContext , MutatingUseContext , NonMutatingUseContext
1818} ;
19- use rustc:: mir:: { self , Location , Mir , Place , Local } ;
19+ use rustc:: mir:: { self , Location , Mir , Local } ;
2020use rustc:: ty:: { RegionVid , TyCtxt } ;
2121use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
2222use rustc_data_structures:: indexed_vec:: IndexVec ;
@@ -41,10 +41,6 @@ crate struct BorrowSet<'tcx> {
4141 /// only need to store one borrow index
4242 crate activation_map : FxHashMap < Location , Vec < BorrowIndex > > ,
4343
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-
4844 /// Map from local to all the borrows on that local
4945 crate local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
5046
@@ -149,7 +145,6 @@ impl<'tcx> BorrowSet<'tcx> {
149145 idx_vec : IndexVec :: new ( ) ,
150146 location_map : Default :: default ( ) ,
151147 activation_map : Default :: default ( ) ,
152- region_map : Default :: default ( ) ,
153148 local_map : Default :: default ( ) ,
154149 pending_activations : Default :: default ( ) ,
155150 locals_state_at_exit :
@@ -164,7 +159,6 @@ impl<'tcx> BorrowSet<'tcx> {
164159 borrows : visitor. idx_vec ,
165160 location_map : visitor. location_map ,
166161 activation_map : visitor. activation_map ,
167- region_map : visitor. region_map ,
168162 local_map : visitor. local_map ,
169163 locals_state_at_exit : visitor. locals_state_at_exit ,
170164 }
@@ -184,7 +178,6 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
184178 idx_vec : IndexVec < BorrowIndex , BorrowData < ' tcx > > ,
185179 location_map : FxHashMap < Location , BorrowIndex > ,
186180 activation_map : FxHashMap < Location , Vec < BorrowIndex > > ,
187- region_map : FxHashMap < RegionVid , FxHashSet < BorrowIndex > > ,
188181 local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
189182
190183 /// 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> {
229222
230223 self . insert_as_pending_if_two_phase ( location, & assigned_place, kind, idx) ;
231224
232- self . region_map . entry ( region) . or_default ( ) . insert ( idx) ;
233225 if let Some ( local) = borrowed_place. root_local ( ) {
234226 self . local_map . entry ( local) . or_default ( ) . insert ( idx) ;
235227 }
@@ -238,68 +230,68 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
238230 self . super_assign ( block, assigned_place, rvalue, location)
239231 }
240232
241- fn visit_place (
233+ fn visit_local (
242234 & mut self ,
243- place : & mir :: Place < ' tcx > ,
235+ temp : & Local ,
244236 context : PlaceContext < ' tcx > ,
245237 location : Location ,
246238 ) {
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+ }
264242
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] ;
276249
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+ ) ;
302268 }
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+ } ;
303295 }
304296 }
305297
0 commit comments