@@ -53,25 +53,22 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
5353 }
5454}
5555
56- /// Every two-phase borrow has *exactly one* use (or else it is not a
57- /// proper two-phase borrow under our current definition). However, not
58- /// all uses are actually ones that activate the reservation.. In
59- /// particular, a shared borrow of a `&mut` does not activate the
60- /// reservation.
56+ /// Location where a two phase borrow is activated, if a borrow
57+ /// is in fact a two phase borrow.
6158#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
62- crate enum TwoPhaseUse {
63- MutActivate ,
64- SharedUse ,
59+ crate enum TwoPhaseActivation {
60+ NotTwoPhase ,
61+ NotActivated ,
62+ ActivatedAt ( Location ) ,
6563}
6664
6765#[ derive( Debug ) ]
6866crate struct BorrowData < ' tcx > {
6967 /// Location where the borrow reservation starts.
7068 /// In many cases, this will be equal to the activation location but not always.
7169 crate reserve_location : Location ,
72- /// Location where the borrow is activated. None if this is not a
73- /// 2-phase borrow.
74- crate activation_location : Option < ( TwoPhaseUse , Location ) > ,
70+ /// Location where the borrow is activated.
71+ crate activation_location : TwoPhaseActivation ,
7572 /// What kind of borrow this is
7673 crate kind : mir:: BorrowKind ,
7774 /// The region for which this borrow is live
@@ -116,19 +113,6 @@ impl<'tcx> BorrowSet<'tcx> {
116113 visitor. visit_basic_block_data ( block, block_data) ;
117114 }
118115
119- // Double check: We should have found an activation for every pending
120- // activation.
121- assert_eq ! (
122- visitor
123- . pending_activations
124- . iter( )
125- . find( |& ( _local, & borrow_index) | visitor. idx_vec[ borrow_index]
126- . activation_location
127- . is_none( ) ) ,
128- None ,
129- "never found an activation for this borrow!" ,
130- ) ;
131-
132116 BorrowSet {
133117 borrows : visitor. idx_vec ,
134118 location_map : visitor. location_map ,
@@ -183,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
183167 kind,
184168 region,
185169 reserve_location : location,
186- activation_location : None ,
170+ activation_location : TwoPhaseActivation :: NotTwoPhase ,
187171 borrowed_place : borrowed_place. clone ( ) ,
188172 assigned_place : assigned_place. clone ( ) ,
189173 } ;
@@ -232,38 +216,43 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
232216 return ;
233217 }
234218
235- if let Some ( other_activation) = borrow_data. activation_location {
219+ if let TwoPhaseActivation :: ActivatedAt ( other_location) =
220+ borrow_data. activation_location {
236221 span_bug ! (
237222 self . mir. source_info( location) . span,
238223 "found two uses for 2-phase borrow temporary {:?}: \
239224 {:?} and {:?}",
240225 temp,
241226 location,
242- other_activation ,
227+ other_location ,
243228 ) ;
244229 }
245230
246231 // Otherwise, this is the unique later use
247232 // that we expect.
248-
249- let two_phase_use;
250-
251- match context {
233+ borrow_data. activation_location = match context {
252234 // The use of TMP in a shared borrow does not
253235 // count as an actual activation.
254236 PlaceContext :: Borrow { kind : mir:: BorrowKind :: Shared , .. } => {
255- two_phase_use = TwoPhaseUse :: SharedUse ;
237+ TwoPhaseActivation :: NotActivated
256238 }
257239 _ => {
258- two_phase_use = TwoPhaseUse :: MutActivate ;
240+ // Double check: This borrow is indeed a two-phase borrow (that is,
241+ // we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
242+ // we've not found any other activations (checked above).
243+ assert_eq ! (
244+ borrow_data. activation_location,
245+ TwoPhaseActivation :: NotActivated ,
246+ "never found an activation for this borrow!" ,
247+ ) ;
248+
259249 self . activation_map
260250 . entry ( location)
261251 . or_insert ( Vec :: new ( ) )
262252 . push ( borrow_index) ;
253+ TwoPhaseActivation :: ActivatedAt ( location)
263254 }
264- }
265-
266- borrow_data. activation_location = Some ( ( two_phase_use, location) ) ;
255+ } ;
267256 }
268257
269258 None => { }
@@ -342,6 +331,11 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
342331 ) ;
343332 } ;
344333
334+ // Consider the borrow not activated to start. When we find an activation, we'll update
335+ // this field.
336+ let borrow_data = & mut self . idx_vec [ borrow_index] ;
337+ borrow_data. activation_location = TwoPhaseActivation :: NotActivated ;
338+
345339 // Insert `temp` into the list of pending activations. From
346340 // now on, we'll be on the lookout for a use of it. Note that
347341 // we are guaranteed that this use will come after the
0 commit comments