@@ -29,7 +29,6 @@ use rustc_data_structures::indexed_vec::Idx;
29
29
30
30
use std:: rc:: Rc ;
31
31
32
- use syntax:: ast;
33
32
use syntax_pos:: Span ;
34
33
35
34
use dataflow:: { do_dataflow, DebugFormatted } ;
@@ -237,7 +236,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
237
236
let mut mbcx = MirBorrowckCtxt {
238
237
tcx : tcx,
239
238
mir : mir,
240
- node_id : id ,
239
+ mir_def_id : def_id ,
241
240
move_data : & mdpe. move_data ,
242
241
param_env : param_env,
243
242
movable_generator,
@@ -250,6 +249,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
250
249
moved_error_reported : FxHashSet ( ) ,
251
250
nonlexical_regioncx : opt_regioncx,
252
251
nonlexical_cause_info : None ,
252
+ borrow_set,
253
253
dominators,
254
254
} ;
255
255
@@ -270,7 +270,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
270
270
pub struct MirBorrowckCtxt < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
271
271
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
272
272
mir : & ' cx Mir < ' tcx > ,
273
- node_id : ast :: NodeId ,
273
+ mir_def_id : DefId ,
274
274
move_data : & ' cx MoveData < ' tcx > ,
275
275
param_env : ParamEnv < ' gcx > ,
276
276
movable_generator : bool ,
@@ -303,6 +303,11 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
303
303
/// find out which CFG points are contained in each borrow region.
304
304
nonlexical_regioncx : Option < Rc < RegionInferenceContext < ' tcx > > > ,
305
305
nonlexical_cause_info : Option < RegionCausalInfo > ,
306
+
307
+ /// The set of borrows extracted from the MIR
308
+ borrow_set : Rc < BorrowSet < ' tcx > > ,
309
+
310
+ /// Dominators for MIR
306
311
dominators : Dominators < BasicBlock > ,
307
312
}
308
313
@@ -544,11 +549,10 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
544
549
545
550
if self . movable_generator {
546
551
// Look for any active borrows to locals
547
- let domain = flow_state. borrows . operator ( ) ;
548
- let data = domain. borrows ( ) ;
552
+ let borrow_set = self . borrow_set . clone ( ) ;
549
553
flow_state. borrows . with_iter_outgoing ( |borrows| {
550
554
for i in borrows {
551
- let borrow = & data [ i] ;
555
+ let borrow = & borrow_set [ i] ;
552
556
self . check_for_local_borrow ( borrow, span) ;
553
557
}
554
558
} ) ;
@@ -560,13 +564,12 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
560
564
// Often, the storage will already have been killed by an explicit
561
565
// StorageDead, but we don't always emit those (notably on unwind paths),
562
566
// so this "extra check" serves as a kind of backup.
563
- let domain = flow_state. borrows . operator ( ) ;
564
- let data = domain. borrows ( ) ;
567
+ let borrow_set = self . borrow_set . clone ( ) ;
565
568
flow_state. borrows . with_iter_outgoing ( |borrows| {
566
569
for i in borrows {
567
- let borrow = & data [ i] ;
570
+ let borrow = & borrow_set [ i] ;
568
571
let context = ContextKind :: StorageDead . new ( loc) ;
569
- self . check_for_invalidation_at_exit ( context, borrow, span, flow_state ) ;
572
+ self . check_for_invalidation_at_exit ( context, borrow, span) ;
570
573
}
571
574
} ) ;
572
575
}
@@ -894,10 +897,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
894
897
this. report_use_while_mutably_borrowed ( context, place_span, borrow)
895
898
}
896
899
ReadKind :: Borrow ( bk) => {
897
- let end_issued_loan_span = flow_state
898
- . borrows
899
- . operator ( )
900
- . opt_region_end_span ( & borrow. region ) ;
900
+ let end_issued_loan_span = this. opt_region_end_span ( & borrow. region ) ;
901
901
error_reported = true ;
902
902
this. report_conflicting_borrow (
903
903
context,
@@ -936,10 +936,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
936
936
937
937
match kind {
938
938
WriteKind :: MutableBorrow ( bk) => {
939
- let end_issued_loan_span = flow_state
940
- . borrows
941
- . operator ( )
942
- . opt_region_end_span ( & borrow. region ) ;
939
+ let end_issued_loan_span = this. opt_region_end_span ( & borrow. region ) ;
943
940
944
941
error_reported = true ;
945
942
this. report_conflicting_borrow (
@@ -956,7 +953,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
956
953
context,
957
954
borrow,
958
955
place_span. 1 ,
959
- flow_state. borrows . operator ( ) ,
960
956
) ;
961
957
}
962
958
WriteKind :: Mutate => {
@@ -1158,7 +1154,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1158
1154
context : Context ,
1159
1155
borrow : & BorrowData < ' tcx > ,
1160
1156
span : Span ,
1161
- flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
1162
1157
) {
1163
1158
debug ! ( "check_for_invalidation_at_exit({:?})" , borrow) ;
1164
1159
let place = & borrow. borrowed_place ;
@@ -1211,7 +1206,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1211
1206
context,
1212
1207
borrow,
1213
1208
span,
1214
- flow_state. borrows . operator ( ) ,
1215
1209
)
1216
1210
}
1217
1211
}
@@ -1266,9 +1260,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1266
1260
// Two-phase borrow support: For each activation that is newly
1267
1261
// generated at this statement, check if it interferes with
1268
1262
// another borrow.
1269
- let borrows = flow_state . borrows . operator ( ) ;
1270
- for & borrow_index in borrows . activations_at_location ( location) {
1271
- let borrow = & borrows . borrows ( ) [ borrow_index] ;
1263
+ let borrow_set = self . borrow_set . clone ( ) ;
1264
+ for & borrow_index in borrow_set . activations_at_location ( location) {
1265
+ let borrow = & borrow_set [ borrow_index] ;
1272
1266
1273
1267
// only mutable borrows should be 2-phase
1274
1268
assert ! ( match borrow. kind {
@@ -1838,6 +1832,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1838
1832
_ => None ,
1839
1833
}
1840
1834
}
1835
+
1836
+ /// Returns the span for the "end point" given region. This will
1837
+ /// return `None` if NLL is enabled, since that concept has no
1838
+ /// meaning there. Otherwise, return region span if it exists and
1839
+ /// span for end of the function if it doesn't exist.
1840
+ pub ( crate ) fn opt_region_end_span ( & self , region : & ty:: Region < ' tcx > ) -> Option < Span > {
1841
+ match self . nonlexical_regioncx {
1842
+ Some ( _) => None ,
1843
+ None => {
1844
+ match self . borrow_set . region_span_map . get ( region) {
1845
+ Some ( span) => Some ( self . tcx . sess . codemap ( ) . end_point ( * span) ) ,
1846
+ None => Some ( self . tcx . sess . codemap ( ) . end_point ( self . mir . span ) )
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1841
1851
}
1842
1852
1843
1853
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -2238,13 +2248,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2238
2248
// FIXME: analogous code in check_loans first maps `place` to
2239
2249
// its base_path.
2240
2250
2241
- let data = flow_state. borrows . operator ( ) . borrows ( ) ;
2242
-
2243
2251
// check for loan restricting path P being used. Accounts for
2244
2252
// borrows of P, P.a.b, etc.
2245
2253
let mut iter_incoming = flow_state. borrows . iter_incoming ( ) ;
2254
+ let borrow_set = self . borrow_set . clone ( ) ;
2246
2255
while let Some ( i) = iter_incoming. next ( ) {
2247
- let borrowed = & data [ i] ;
2256
+ let borrowed = & borrow_set [ i] ;
2248
2257
2249
2258
if self . places_conflict ( & borrowed. borrowed_place , place, access) {
2250
2259
debug ! (
0 commit comments