@@ -168,10 +168,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
168
168
}
169
169
170
170
fn check_mod_liveness ( tcx : TyCtxt < ' _ > , module_def_id : LocalDefId ) {
171
- tcx. hir ( ) . visit_item_likes_in_module (
172
- module_def_id,
173
- & mut IrMaps :: new ( tcx, module_def_id) . as_deep_visitor ( ) ,
174
- ) ;
171
+ tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut IrMaps :: new ( tcx) . as_deep_visitor ( ) ) ;
175
172
}
176
173
177
174
pub fn provide ( providers : & mut Providers ) {
@@ -227,7 +224,6 @@ enum VarKind {
227
224
228
225
struct IrMaps < ' tcx > {
229
226
tcx : TyCtxt < ' tcx > ,
230
- body_owner : LocalDefId ,
231
227
live_node_map : HirIdMap < LiveNode > ,
232
228
variable_map : HirIdMap < Variable > ,
233
229
capture_info_map : HirIdMap < Rc < Vec < CaptureInfo > > > ,
@@ -236,10 +232,9 @@ struct IrMaps<'tcx> {
236
232
}
237
233
238
234
impl IrMaps < ' tcx > {
239
- fn new ( tcx : TyCtxt < ' tcx > , body_owner : LocalDefId ) -> IrMaps < ' tcx > {
235
+ fn new ( tcx : TyCtxt < ' tcx > ) -> IrMaps < ' tcx > {
240
236
IrMaps {
241
237
tcx,
242
- body_owner,
243
238
live_node_map : HirIdMap :: default ( ) ,
244
239
variable_map : HirIdMap :: default ( ) ,
245
240
capture_info_map : Default :: default ( ) ,
@@ -316,7 +311,7 @@ fn visit_fn<'tcx>(
316
311
317
312
// swap in a new set of IR maps for this function body:
318
313
let def_id = ir. tcx . hir ( ) . local_def_id ( id) ;
319
- let mut fn_maps = IrMaps :: new ( ir. tcx , def_id ) ;
314
+ let mut fn_maps = IrMaps :: new ( ir. tcx ) ;
320
315
321
316
// Don't run unused pass for #[derive()]
322
317
if let FnKind :: Method ( ..) = fk {
@@ -448,10 +443,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
448
443
} ) ) ;
449
444
}
450
445
ir. set_captures ( expr. hir_id , call_caps) ;
451
- let old_body_owner = ir. body_owner ;
452
- ir. body_owner = closure_def_id;
453
446
intravisit:: walk_expr ( ir, expr) ;
454
- ir. body_owner = old_body_owner;
455
447
}
456
448
457
449
// live nodes required for interesting control flow:
@@ -605,6 +597,7 @@ const ACC_USE: u32 = 4;
605
597
606
598
struct Liveness < ' a , ' tcx > {
607
599
ir : & ' a mut IrMaps < ' tcx > ,
600
+ body_owner : LocalDefId ,
608
601
typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
609
602
param_env : ty:: ParamEnv < ' tcx > ,
610
603
successors : IndexVec < LiveNode , LiveNode > ,
@@ -626,9 +619,9 @@ struct Liveness<'a, 'tcx> {
626
619
}
627
620
628
621
impl < ' a , ' tcx > Liveness < ' a , ' tcx > {
629
- fn new ( ir : & ' a mut IrMaps < ' tcx > , def_id : LocalDefId ) -> Liveness < ' a , ' tcx > {
630
- let typeck_results = ir. tcx . typeck ( def_id ) ;
631
- let param_env = ir. tcx . param_env ( def_id ) ;
622
+ fn new ( ir : & ' a mut IrMaps < ' tcx > , body_owner : LocalDefId ) -> Liveness < ' a , ' tcx > {
623
+ let typeck_results = ir. tcx . typeck ( body_owner ) ;
624
+ let param_env = ir. tcx . param_env ( body_owner ) ;
632
625
633
626
let closure_ln = ir. add_live_node ( ClosureNode ) ;
634
627
let exit_ln = ir. add_live_node ( ExitNode ) ;
@@ -638,6 +631,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
638
631
639
632
Liveness {
640
633
ir,
634
+ body_owner,
641
635
typeck_results,
642
636
param_env,
643
637
successors : IndexVec :: from_elem_n ( INVALID_NODE , num_live_nodes) ,
@@ -893,12 +887,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
893
887
// if they are live on the entry to the closure, since only the closure
894
888
// itself can access them on subsequent calls.
895
889
896
- if let Some ( upvars) = self . ir . tcx . upvars_mentioned ( self . ir . body_owner ) {
890
+ if let Some ( upvars) = self . ir . tcx . upvars_mentioned ( self . body_owner ) {
897
891
// Mark upvars captured by reference as used after closure exits.
898
892
for ( & var_hir_id, upvar) in upvars. iter ( ) . rev ( ) {
899
893
let upvar_id = ty:: UpvarId {
900
894
var_path : ty:: UpvarPath { hir_id : var_hir_id } ,
901
- closure_expr_id : self . ir . body_owner ,
895
+ closure_expr_id : self . body_owner ,
902
896
} ;
903
897
match self . typeck_results . upvar_capture ( upvar_id) {
904
898
ty:: UpvarCapture :: ByRef ( _) => {
@@ -1565,15 +1559,15 @@ impl<'tcx> Liveness<'_, 'tcx> {
1565
1559
}
1566
1560
1567
1561
fn warn_about_unused_upvars ( & self , entry_ln : LiveNode ) {
1568
- let upvars = match self . ir . tcx . upvars_mentioned ( self . ir . body_owner ) {
1562
+ let upvars = match self . ir . tcx . upvars_mentioned ( self . body_owner ) {
1569
1563
None => return ,
1570
1564
Some ( upvars) => upvars,
1571
1565
} ;
1572
1566
for ( & var_hir_id, upvar) in upvars. iter ( ) {
1573
1567
let var = self . variable ( var_hir_id, upvar. span ) ;
1574
1568
let upvar_id = ty:: UpvarId {
1575
1569
var_path : ty:: UpvarPath { hir_id : var_hir_id } ,
1576
- closure_expr_id : self . ir . body_owner ,
1570
+ closure_expr_id : self . body_owner ,
1577
1571
} ;
1578
1572
match self . typeck_results . upvar_capture ( upvar_id) {
1579
1573
ty:: UpvarCapture :: ByValue ( _) => { }
0 commit comments