@@ -53,25 +53,22 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
53
53
}
54
54
}
55
55
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.
61
58
#[ 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 ) ,
65
63
}
66
64
67
65
#[ derive( Debug ) ]
68
66
crate struct BorrowData < ' tcx > {
69
67
/// Location where the borrow reservation starts.
70
68
/// In many cases, this will be equal to the activation location but not always.
71
69
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 ,
75
72
/// What kind of borrow this is
76
73
crate kind : mir:: BorrowKind ,
77
74
/// The region for which this borrow is live
@@ -116,19 +113,6 @@ impl<'tcx> BorrowSet<'tcx> {
116
113
visitor. visit_basic_block_data ( block, block_data) ;
117
114
}
118
115
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
-
132
116
BorrowSet {
133
117
borrows : visitor. idx_vec ,
134
118
location_map : visitor. location_map ,
@@ -183,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
183
167
kind,
184
168
region,
185
169
reserve_location : location,
186
- activation_location : None ,
170
+ activation_location : TwoPhaseActivation :: NotTwoPhase ,
187
171
borrowed_place : borrowed_place. clone ( ) ,
188
172
assigned_place : assigned_place. clone ( ) ,
189
173
} ;
@@ -232,38 +216,43 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
232
216
return ;
233
217
}
234
218
235
- if let Some ( other_activation) = borrow_data. activation_location {
219
+ if let TwoPhaseActivation :: ActivatedAt ( other_location) =
220
+ borrow_data. activation_location {
236
221
span_bug ! (
237
222
self . mir. source_info( location) . span,
238
223
"found two uses for 2-phase borrow temporary {:?}: \
239
224
{:?} and {:?}",
240
225
temp,
241
226
location,
242
- other_activation ,
227
+ other_location ,
243
228
) ;
244
229
}
245
230
246
231
// Otherwise, this is the unique later use
247
232
// that we expect.
248
-
249
- let two_phase_use;
250
-
251
- match context {
233
+ borrow_data. activation_location = match context {
252
234
// The use of TMP in a shared borrow does not
253
235
// count as an actual activation.
254
236
PlaceContext :: Borrow { kind : mir:: BorrowKind :: Shared , .. } => {
255
- two_phase_use = TwoPhaseUse :: SharedUse ;
237
+ TwoPhaseActivation :: NotActivated
256
238
}
257
239
_ => {
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
+
259
249
self . activation_map
260
250
. entry ( location)
261
251
. or_insert ( Vec :: new ( ) )
262
252
. push ( borrow_index) ;
253
+ TwoPhaseActivation :: ActivatedAt ( location)
263
254
}
264
- }
265
-
266
- borrow_data. activation_location = Some ( ( two_phase_use, location) ) ;
255
+ } ;
267
256
}
268
257
269
258
None => { }
@@ -342,6 +331,11 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
342
331
) ;
343
332
} ;
344
333
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
+
345
339
// Insert `temp` into the list of pending activations. From
346
340
// now on, we'll be on the lookout for a use of it. Note that
347
341
// we are guaranteed that this use will come after the
0 commit comments