@@ -12,18 +12,13 @@ use borrow_check::borrow_set::{BorrowSet, BorrowData};
12
12
use borrow_check:: place_ext:: PlaceExt ;
13
13
14
14
use rustc;
15
- use rustc:: hir;
16
- use rustc:: hir:: def_id:: DefId ;
17
- use rustc:: middle:: region;
18
15
use rustc:: mir:: { self , Location , Place , Mir } ;
19
16
use rustc:: ty:: TyCtxt ;
20
- use rustc:: ty:: { RegionKind , RegionVid } ;
21
- use rustc:: ty:: RegionKind :: ReScope ;
17
+ use rustc:: ty:: RegionVid ;
22
18
23
19
use rustc_data_structures:: bit_set:: { BitSet , BitSetOperator } ;
24
20
use rustc_data_structures:: fx:: FxHashMap ;
25
21
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
26
- use rustc_data_structures:: sync:: Lrc ;
27
22
28
23
use dataflow:: { BitDenotation , BlockSets , InitialFlow } ;
29
24
pub use dataflow:: indexes:: BorrowIndex ;
@@ -42,8 +37,6 @@ use std::rc::Rc;
42
37
pub struct Borrows < ' a , ' gcx : ' tcx , ' tcx : ' a > {
43
38
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
44
39
mir : & ' a Mir < ' tcx > ,
45
- scope_tree : Lrc < region:: ScopeTree > ,
46
- root_scope : Option < region:: Scope > ,
47
40
48
41
borrow_set : Rc < BorrowSet < ' tcx > > ,
49
42
borrows_out_of_scope_at_location : FxHashMap < Location , Vec < BorrowIndex > > ,
@@ -150,18 +143,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
150
143
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
151
144
mir : & ' a Mir < ' tcx > ,
152
145
nonlexical_regioncx : Rc < RegionInferenceContext < ' tcx > > ,
153
- def_id : DefId ,
154
- body_id : Option < hir:: BodyId > ,
155
146
borrow_set : & Rc < BorrowSet < ' tcx > > ,
156
147
) -> 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
-
165
148
let mut borrows_out_of_scope_at_location = FxHashMap :: default ( ) ;
166
149
for ( borrow_index, borrow_data) in borrow_set. borrows . iter_enumerated ( ) {
167
150
let borrow_region = borrow_data. region . to_region_vid ( ) ;
@@ -177,8 +160,6 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
177
160
mir : mir,
178
161
borrow_set : borrow_set. clone ( ) ,
179
162
borrows_out_of_scope_at_location,
180
- scope_tree,
181
- root_scope,
182
163
_nonlexical_regioncx : nonlexical_regioncx,
183
164
}
184
165
}
@@ -277,22 +258,13 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
277
258
panic ! ( "could not find BorrowIndex for location {:?}" , location) ;
278
259
} ) ;
279
260
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
+ ) ;
296
268
sets. gen ( * index) ;
297
269
298
270
// Issue #46746: Two-phase borrows handles
@@ -349,52 +321,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
349
321
self . kill_loans_out_of_scope_at_location ( sets, location) ;
350
322
}
351
323
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 ) { }
398
325
399
326
fn propagate_call_return ( & self ,
400
327
_in_out : & mut BitSet < BorrowIndex > ,
0 commit comments