@@ -29,7 +29,6 @@ use rustc_data_structures::indexed_vec::Idx;
2929
3030use std:: rc:: Rc ;
3131
32- use syntax:: ast;
3332use syntax_pos:: Span ;
3433
3534use dataflow:: { do_dataflow, DebugFormatted } ;
@@ -237,7 +236,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
237236 let mut mbcx = MirBorrowckCtxt {
238237 tcx : tcx,
239238 mir : mir,
240- node_id : id ,
239+ mir_def_id : def_id ,
241240 move_data : & mdpe. move_data ,
242241 param_env : param_env,
243242 movable_generator,
@@ -250,6 +249,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
250249 moved_error_reported : FxHashSet ( ) ,
251250 nonlexical_regioncx : opt_regioncx,
252251 nonlexical_cause_info : None ,
252+ borrow_set,
253253 dominators,
254254 } ;
255255
@@ -270,7 +270,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
270270pub struct MirBorrowckCtxt < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
271271 tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
272272 mir : & ' cx Mir < ' tcx > ,
273- node_id : ast :: NodeId ,
273+ mir_def_id : DefId ,
274274 move_data : & ' cx MoveData < ' tcx > ,
275275 param_env : ParamEnv < ' gcx > ,
276276 movable_generator : bool ,
@@ -303,6 +303,11 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
303303 /// find out which CFG points are contained in each borrow region.
304304 nonlexical_regioncx : Option < Rc < RegionInferenceContext < ' tcx > > > ,
305305 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
306311 dominators : Dominators < BasicBlock > ,
307312}
308313
@@ -544,11 +549,10 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
544549
545550 if self . movable_generator {
546551 // 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 ( ) ;
549553 flow_state. borrows . with_iter_outgoing ( |borrows| {
550554 for i in borrows {
551- let borrow = & data [ i] ;
555+ let borrow = & borrow_set [ i] ;
552556 self . check_for_local_borrow ( borrow, span) ;
553557 }
554558 } ) ;
@@ -560,13 +564,12 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
560564 // Often, the storage will already have been killed by an explicit
561565 // StorageDead, but we don't always emit those (notably on unwind paths),
562566 // 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 ( ) ;
565568 flow_state. borrows . with_iter_outgoing ( |borrows| {
566569 for i in borrows {
567- let borrow = & data [ i] ;
570+ let borrow = & borrow_set [ i] ;
568571 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) ;
570573 }
571574 } ) ;
572575 }
@@ -894,10 +897,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
894897 this. report_use_while_mutably_borrowed ( context, place_span, borrow)
895898 }
896899 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 ) ;
901901 error_reported = true ;
902902 this. report_conflicting_borrow (
903903 context,
@@ -936,10 +936,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
936936
937937 match kind {
938938 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 ) ;
943940
944941 error_reported = true ;
945942 this. report_conflicting_borrow (
@@ -956,7 +953,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
956953 context,
957954 borrow,
958955 place_span. 1 ,
959- flow_state. borrows . operator ( ) ,
960956 ) ;
961957 }
962958 WriteKind :: Mutate => {
@@ -1158,7 +1154,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11581154 context : Context ,
11591155 borrow : & BorrowData < ' tcx > ,
11601156 span : Span ,
1161- flow_state : & Flows < ' cx , ' gcx , ' tcx > ,
11621157 ) {
11631158 debug ! ( "check_for_invalidation_at_exit({:?})" , borrow) ;
11641159 let place = & borrow. borrowed_place ;
@@ -1211,7 +1206,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12111206 context,
12121207 borrow,
12131208 span,
1214- flow_state. borrows . operator ( ) ,
12151209 )
12161210 }
12171211 }
@@ -1266,9 +1260,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12661260 // Two-phase borrow support: For each activation that is newly
12671261 // generated at this statement, check if it interferes with
12681262 // 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] ;
12721266
12731267 // only mutable borrows should be 2-phase
12741268 assert ! ( match borrow. kind {
@@ -1838,6 +1832,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18381832 _ => None ,
18391833 }
18401834 }
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+ }
18411851}
18421852
18431853#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -2238,13 +2248,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22382248 // FIXME: analogous code in check_loans first maps `place` to
22392249 // its base_path.
22402250
2241- let data = flow_state. borrows . operator ( ) . borrows ( ) ;
2242-
22432251 // check for loan restricting path P being used. Accounts for
22442252 // borrows of P, P.a.b, etc.
22452253 let mut iter_incoming = flow_state. borrows . iter_incoming ( ) ;
2254+ let borrow_set = self . borrow_set . clone ( ) ;
22462255 while let Some ( i) = iter_incoming. next ( ) {
2247- let borrowed = & data [ i] ;
2256+ let borrowed = & borrow_set [ i] ;
22482257
22492258 if self . places_conflict ( & borrowed. borrowed_place , place, access) {
22502259 debug ! (
0 commit comments