@@ -12,18 +12,13 @@ use borrow_check::borrow_set::{BorrowSet, BorrowData};
1212use borrow_check:: place_ext:: PlaceExt ;
1313
1414use rustc;
15- use rustc:: hir;
16- use rustc:: hir:: def_id:: DefId ;
17- use rustc:: middle:: region;
1815use rustc:: mir:: { self , Location , Place , Mir } ;
1916use rustc:: ty:: TyCtxt ;
20- use rustc:: ty:: { RegionKind , RegionVid } ;
21- use rustc:: ty:: RegionKind :: ReScope ;
17+ use rustc:: ty:: RegionVid ;
2218
2319use rustc_data_structures:: bit_set:: { BitSet , BitSetOperator } ;
2420use rustc_data_structures:: fx:: FxHashMap ;
2521use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
26- use rustc_data_structures:: sync:: Lrc ;
2722
2823use dataflow:: { BitDenotation , BlockSets , InitialFlow } ;
2924pub use dataflow:: indexes:: BorrowIndex ;
@@ -42,8 +37,6 @@ use std::rc::Rc;
4237pub struct Borrows < ' a , ' gcx : ' tcx , ' tcx : ' a > {
4338 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
4439 mir : & ' a Mir < ' tcx > ,
45- scope_tree : Lrc < region:: ScopeTree > ,
46- root_scope : Option < region:: Scope > ,
4740
4841 borrow_set : Rc < BorrowSet < ' tcx > > ,
4942 borrows_out_of_scope_at_location : FxHashMap < Location , Vec < BorrowIndex > > ,
@@ -150,18 +143,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
150143 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
151144 mir : & ' a Mir < ' tcx > ,
152145 nonlexical_regioncx : Rc < RegionInferenceContext < ' tcx > > ,
153- def_id : DefId ,
154- body_id : Option < hir:: BodyId > ,
155146 borrow_set : & Rc < BorrowSet < ' tcx > > ,
156147 ) -> Self {
157- let scope_tree = tcx. region_scope_tree ( def_id) ;
158- let root_scope = body_id. map ( |body_id| {
159- region:: Scope {
160- id : tcx. hir . body ( body_id) . value . hir_id . local_id ,
161- data : region:: ScopeData :: CallSite
162- }
163- } ) ;
164-
165148 let mut borrows_out_of_scope_at_location = FxHashMap :: default ( ) ;
166149 for ( borrow_index, borrow_data) in borrow_set. borrows . iter_enumerated ( ) {
167150 let borrow_region = borrow_data. region . to_region_vid ( ) ;
@@ -177,8 +160,6 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
177160 mir : mir,
178161 borrow_set : borrow_set. clone ( ) ,
179162 borrows_out_of_scope_at_location,
180- scope_tree,
181- root_scope,
182163 _nonlexical_regioncx : nonlexical_regioncx,
183164 }
184165 }
@@ -277,22 +258,13 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
277258 panic ! ( "could not find BorrowIndex for location {:?}" , location) ;
278259 } ) ;
279260
280- if let RegionKind :: ReEmpty = region {
281- // If the borrowed value dies before the borrow is used, the region for
282- // the borrow can be empty. Don't track the borrow in that case.
283- debug ! ( "Borrows::statement_effect_on_borrows \
284- location: {:?} stmt: {:?} has empty region, killing {:?}",
285- location, stmt. kind, index) ;
286- sets. kill ( * index) ;
287- return
288- } else {
289- debug ! ( "Borrows::statement_effect_on_borrows location: {:?} stmt: {:?}" ,
290- location, stmt. kind) ;
291- }
292-
293- assert ! ( self . borrow_set. region_map. get( region) . unwrap_or_else( || {
294- panic!( "could not find BorrowIndexs for region {:?}" , region) ;
295- } ) . contains( & index) ) ;
261+ assert ! ( self . borrow_set. region_map
262+ . get( & region. to_region_vid( ) )
263+ . unwrap_or_else( || {
264+ panic!( "could not find BorrowIndexs for RegionVid {:?}" , region) ;
265+ } )
266+ . contains( & index)
267+ ) ;
296268 sets. gen ( * index) ;
297269
298270 // Issue #46746: Two-phase borrows handles
@@ -349,52 +321,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
349321 self . kill_loans_out_of_scope_at_location ( sets, location) ;
350322 }
351323
352- fn terminator_effect ( & self , sets : & mut BlockSets < BorrowIndex > , location : Location ) {
353- debug ! ( "Borrows::terminator_effect sets: {:?} location: {:?}" , sets, location) ;
354-
355- let block = & self . mir . basic_blocks ( ) . get ( location. block ) . unwrap_or_else ( || {
356- panic ! ( "could not find block at location {:?}" , location) ;
357- } ) ;
358-
359- let term = block. terminator ( ) ;
360- match term. kind {
361- mir:: TerminatorKind :: Resume |
362- mir:: TerminatorKind :: Return |
363- mir:: TerminatorKind :: GeneratorDrop => {
364- // When we return from the function, then all `ReScope`-style regions
365- // are guaranteed to have ended.
366- // Normally, there would be `EndRegion` statements that come before,
367- // and hence most of these loans will already be dead -- but, in some cases
368- // like unwind paths, we do not always emit `EndRegion` statements, so we
369- // add some kills here as a "backup" and to avoid spurious error messages.
370- for ( borrow_index, borrow_data) in self . borrow_set . borrows . iter_enumerated ( ) {
371- if let ReScope ( scope) = borrow_data. region {
372- // Check that the scope is not actually a scope from a function that is
373- // a parent of our closure. Note that the CallSite scope itself is
374- // *outside* of the closure, for some weird reason.
375- if let Some ( root_scope) = self . root_scope {
376- if * scope != root_scope &&
377- self . scope_tree . is_subscope_of ( * scope, root_scope)
378- {
379- sets. kill ( borrow_index) ;
380- }
381- }
382- }
383- }
384- }
385- mir:: TerminatorKind :: Abort |
386- mir:: TerminatorKind :: SwitchInt { ..} |
387- mir:: TerminatorKind :: Drop { ..} |
388- mir:: TerminatorKind :: DropAndReplace { ..} |
389- mir:: TerminatorKind :: Call { ..} |
390- mir:: TerminatorKind :: Assert { ..} |
391- mir:: TerminatorKind :: Yield { ..} |
392- mir:: TerminatorKind :: Goto { ..} |
393- mir:: TerminatorKind :: FalseEdges { ..} |
394- mir:: TerminatorKind :: FalseUnwind { ..} |
395- mir:: TerminatorKind :: Unreachable => { }
396- }
397- }
324+ fn terminator_effect ( & self , _: & mut BlockSets < BorrowIndex > , _: Location ) { }
398325
399326 fn propagate_call_return ( & self ,
400327 _in_out : & mut BitSet < BorrowIndex > ,
0 commit comments