9
9
// except according to those terms.
10
10
11
11
use borrow_check:: place_ext:: PlaceExt ;
12
+ use borrow_check:: nll:: ToRegionVid ;
12
13
use dataflow:: indexes:: BorrowIndex ;
13
14
use dataflow:: move_paths:: MoveData ;
14
15
use rustc:: mir:: traversal;
15
16
use rustc:: mir:: visit:: {
16
17
PlaceContext , Visitor , NonUseContext , MutatingUseContext , NonMutatingUseContext
17
18
} ;
18
19
use rustc:: mir:: { self , Location , Mir , Place , Local } ;
19
- use rustc:: ty:: { Region , TyCtxt } ;
20
+ use rustc:: ty:: { RegionVid , TyCtxt } ;
20
21
use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
21
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
22
23
use rustc_data_structures:: bit_set:: BitSet ;
@@ -42,7 +43,7 @@ crate struct BorrowSet<'tcx> {
42
43
43
44
/// Every borrow has a region; this maps each such regions back to
44
45
/// its borrow-indexes.
45
- crate region_map : FxHashMap < Region < ' tcx > , FxHashSet < BorrowIndex > > ,
46
+ crate region_map : FxHashMap < RegionVid , FxHashSet < BorrowIndex > > ,
46
47
47
48
/// Map from local to all the borrows on that local
48
49
crate local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
@@ -77,7 +78,7 @@ crate struct BorrowData<'tcx> {
77
78
/// What kind of borrow this is
78
79
crate kind : mir:: BorrowKind ,
79
80
/// The region for which this borrow is live
80
- crate region : Region < ' tcx > ,
81
+ crate region : RegionVid ,
81
82
/// Place from which we are borrowing
82
83
crate borrowed_place : mir:: Place < ' tcx > ,
83
84
/// Place to which the borrow was stored
@@ -92,13 +93,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
92
93
mir:: BorrowKind :: Unique => "uniq " ,
93
94
mir:: BorrowKind :: Mut { .. } => "mut " ,
94
95
} ;
95
- let region = self . region . to_string ( ) ;
96
- let separator = if !region. is_empty ( ) {
97
- " "
98
- } else {
99
- ""
100
- } ;
101
- write ! ( w, "&{}{}{}{:?}" , region, separator, kind, self . borrowed_place)
96
+ write ! ( w, "&{:?} {}{:?}" , self . region, kind, self . borrowed_place)
102
97
}
103
98
}
104
99
@@ -189,7 +184,7 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
189
184
idx_vec : IndexVec < BorrowIndex , BorrowData < ' tcx > > ,
190
185
location_map : FxHashMap < Location , BorrowIndex > ,
191
186
activation_map : FxHashMap < Location , Vec < BorrowIndex > > ,
192
- region_map : FxHashMap < Region < ' tcx > , FxHashSet < BorrowIndex > > ,
187
+ region_map : FxHashMap < RegionVid , FxHashSet < BorrowIndex > > ,
193
188
local_map : FxHashMap < mir:: Local , FxHashSet < BorrowIndex > > ,
194
189
195
190
/// When we encounter a 2-phase borrow statement, it will always
@@ -219,6 +214,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
219
214
return ;
220
215
}
221
216
217
+ let region = region. to_region_vid ( ) ;
218
+
222
219
let borrow = BorrowData {
223
220
kind,
224
221
region,
@@ -230,7 +227,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
230
227
let idx = self . idx_vec . push ( borrow) ;
231
228
self . location_map . insert ( location, idx) ;
232
229
233
- self . insert_as_pending_if_two_phase ( location, & assigned_place, region , kind, idx) ;
230
+ self . insert_as_pending_if_two_phase ( location, & assigned_place, kind, idx) ;
234
231
235
232
self . region_map . entry ( region) . or_default ( ) . insert ( idx) ;
236
233
if let Some ( local) = borrowed_place. root_local ( ) {
@@ -314,7 +311,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
314
311
let borrow_data = & self . idx_vec [ borrow_index] ;
315
312
assert_eq ! ( borrow_data. reserve_location, location) ;
316
313
assert_eq ! ( borrow_data. kind, kind) ;
317
- assert_eq ! ( borrow_data. region, region) ;
314
+ assert_eq ! ( borrow_data. region, region. to_region_vid ( ) ) ;
318
315
assert_eq ! ( borrow_data. borrowed_place, * place) ;
319
316
}
320
317
@@ -347,13 +344,12 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
347
344
& mut self ,
348
345
start_location : Location ,
349
346
assigned_place : & mir:: Place < ' tcx > ,
350
- region : Region < ' tcx > ,
351
347
kind : mir:: BorrowKind ,
352
348
borrow_index : BorrowIndex ,
353
349
) {
354
350
debug ! (
355
- "Borrows::insert_as_pending_if_two_phase({:?}, {:?}, {:?}, {:?} )" ,
356
- start_location, assigned_place, region , borrow_index,
351
+ "Borrows::insert_as_pending_if_two_phase({:?}, {:?}, {:?})" ,
352
+ start_location, assigned_place, borrow_index,
357
353
) ;
358
354
359
355
if !self . allow_two_phase_borrow ( kind) {
0 commit comments