@@ -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 } ;
@@ -236,7 +235,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
236
235
let mut mbcx = MirBorrowckCtxt {
237
236
tcx : tcx,
238
237
mir : mir,
239
- node_id : id ,
238
+ mir_def_id : def_id ,
240
239
move_data : & mdpe. move_data ,
241
240
param_env : param_env,
242
241
movable_generator,
@@ -249,6 +248,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
249
248
moved_error_reported : FxHashSet ( ) ,
250
249
nonlexical_regioncx : opt_regioncx,
251
250
nonlexical_cause_info : None ,
251
+ borrow_set,
252
252
dominators,
253
253
} ;
254
254
@@ -269,7 +269,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
269
269
pub struct MirBorrowckCtxt < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
270
270
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
271
271
mir : & ' cx Mir < ' tcx > ,
272
- node_id : ast :: NodeId ,
272
+ mir_def_id : DefId ,
273
273
move_data : & ' cx MoveData < ' tcx > ,
274
274
param_env : ParamEnv < ' gcx > ,
275
275
movable_generator : bool ,
@@ -302,6 +302,11 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
302
302
/// find out which CFG points are contained in each borrow region.
303
303
nonlexical_regioncx : Option < Rc < RegionInferenceContext < ' tcx > > > ,
304
304
nonlexical_cause_info : Option < RegionCausalInfo > ,
305
+
306
+ /// The set of borrows extracted from the MIR
307
+ borrow_set : Rc < BorrowSet < ' tcx > > ,
308
+
309
+ /// Dominators for MIR
305
310
dominators : Dominators < BasicBlock > ,
306
311
}
307
312
@@ -543,11 +548,10 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
543
548
544
549
if self . movable_generator {
545
550
// Look for any active borrows to locals
546
- let domain = flow_state. borrows . operator ( ) ;
547
- let data = domain. borrows ( ) ;
551
+ let borrow_set = self . borrow_set . clone ( ) ;
548
552
flow_state. borrows . with_iter_outgoing ( |borrows| {
549
553
for i in borrows {
550
- let borrow = & data [ i] ;
554
+ let borrow = & borrow_set [ i] ;
551
555
self . check_for_local_borrow ( borrow, span) ;
552
556
}
553
557
} ) ;
@@ -559,13 +563,12 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
559
563
// Often, the storage will already have been killed by an explicit
560
564
// StorageDead, but we don't always emit those (notably on unwind paths),
561
565
// so this "extra check" serves as a kind of backup.
562
- let domain = flow_state. borrows . operator ( ) ;
563
- let data = domain. borrows ( ) ;
566
+ let borrow_set = self . borrow_set . clone ( ) ;
564
567
flow_state. borrows . with_iter_outgoing ( |borrows| {
565
568
for i in borrows {
566
- let borrow = & data [ i] ;
569
+ let borrow = & borrow_set [ i] ;
567
570
let context = ContextKind :: StorageDead . new ( loc) ;
568
- self . check_for_invalidation_at_exit ( context, borrow, span, flow_state ) ;
571
+ self . check_for_invalidation_at_exit ( context, borrow, span) ;
569
572
}
570
573
} ) ;
571
574
}
@@ -893,10 +896,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
893
896
this. report_use_while_mutably_borrowed ( context, place_span, borrow)
894
897
}
895
898
ReadKind :: Borrow ( bk) => {
896
- let end_issued_loan_span = flow_state
897
- . borrows
898
- . operator ( )
899
- . opt_region_end_span ( & borrow. region ) ;
899
+ let end_issued_loan_span = this. opt_region_end_span ( & borrow. region ) ;
900
900
error_reported = true ;
901
901
this. report_conflicting_borrow (
902
902
context,
@@ -935,10 +935,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
935
935
936
936
match kind {
937
937
WriteKind :: MutableBorrow ( bk) => {
938
- let end_issued_loan_span = flow_state
939
- . borrows
940
- . operator ( )
941
- . opt_region_end_span ( & borrow. region ) ;
938
+ let end_issued_loan_span = this. opt_region_end_span ( & borrow. region ) ;
942
939
943
940
error_reported = true ;
944
941
this. report_conflicting_borrow (
@@ -955,7 +952,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
955
952
context,
956
953
borrow,
957
954
place_span. 1 ,
958
- flow_state. borrows . operator ( ) ,
959
955
) ;
960
956
}
961
957
WriteKind :: Mutate => {
@@ -1157,7 +1153,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1157
1153
context : Context ,
1158
1154
borrow : & BorrowData < ' tcx > ,
1159
1155
span : Span ,
1160
- flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
1161
1156
) {
1162
1157
debug ! ( "check_for_invalidation_at_exit({:?})" , borrow) ;
1163
1158
let place = & borrow. borrowed_place ;
@@ -1210,7 +1205,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1210
1205
context,
1211
1206
borrow,
1212
1207
span,
1213
- flow_state. borrows . operator ( ) ,
1214
1208
)
1215
1209
}
1216
1210
}
@@ -1265,9 +1259,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1265
1259
// Two-phase borrow support: For each activation that is newly
1266
1260
// generated at this statement, check if it interferes with
1267
1261
// another borrow.
1268
- let borrows = flow_state . borrows . operator ( ) ;
1269
- for & borrow_index in borrows . activations_at_location ( location) {
1270
- let borrow = & borrows . borrows ( ) [ borrow_index] ;
1262
+ let borrow_set = self . borrow_set . clone ( ) ;
1263
+ for & borrow_index in borrow_set . activations_at_location ( location) {
1264
+ let borrow = & borrow_set [ borrow_index] ;
1271
1265
1272
1266
// only mutable borrows should be 2-phase
1273
1267
assert ! ( match borrow. kind {
@@ -1782,6 +1776,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1782
1776
_ => None ,
1783
1777
}
1784
1778
}
1779
+
1780
+ /// Returns the span for the "end point" given region. This will
1781
+ /// return `None` if NLL is enabled, since that concept has no
1782
+ /// meaning there. Otherwise, return region span if it exists and
1783
+ /// span for end of the function if it doesn't exist.
1784
+ pub ( crate ) fn opt_region_end_span ( & self , region : & ty:: Region < ' tcx > ) -> Option < Span > {
1785
+ match self . nonlexical_regioncx {
1786
+ Some ( _) => None ,
1787
+ None => {
1788
+ match self . borrow_set . region_span_map . get ( region) {
1789
+ Some ( span) => Some ( self . tcx . sess . codemap ( ) . end_point ( * span) ) ,
1790
+ None => Some ( self . tcx . sess . codemap ( ) . end_point ( self . mir . span ) )
1791
+ }
1792
+ }
1793
+ }
1794
+ }
1785
1795
}
1786
1796
1787
1797
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -2182,13 +2192,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2182
2192
// FIXME: analogous code in check_loans first maps `place` to
2183
2193
// its base_path.
2184
2194
2185
- let data = flow_state. borrows . operator ( ) . borrows ( ) ;
2186
-
2187
2195
// check for loan restricting path P being used. Accounts for
2188
2196
// borrows of P, P.a.b, etc.
2189
2197
let mut iter_incoming = flow_state. borrows . iter_incoming ( ) ;
2198
+ let borrow_set = self . borrow_set . clone ( ) ;
2190
2199
while let Some ( i) = iter_incoming. next ( ) {
2191
- let borrowed = & data [ i] ;
2200
+ let borrowed = & borrow_set [ i] ;
2192
2201
2193
2202
if self . places_conflict ( & borrowed. borrowed_place , place, access) {
2194
2203
debug ! (
0 commit comments