@@ -168,10 +168,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
168168}
169169
170170fn 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 ( ) ) ;
175172}
176173
177174pub fn provide ( providers : & mut Providers ) {
@@ -227,7 +224,6 @@ enum VarKind {
227224
228225struct IrMaps < ' tcx > {
229226 tcx : TyCtxt < ' tcx > ,
230- body_owner : LocalDefId ,
231227 live_node_map : HirIdMap < LiveNode > ,
232228 variable_map : HirIdMap < Variable > ,
233229 capture_info_map : HirIdMap < Rc < Vec < CaptureInfo > > > ,
@@ -236,10 +232,9 @@ struct IrMaps<'tcx> {
236232}
237233
238234impl IrMaps < ' tcx > {
239- fn new ( tcx : TyCtxt < ' tcx > , body_owner : LocalDefId ) -> IrMaps < ' tcx > {
235+ fn new ( tcx : TyCtxt < ' tcx > ) -> IrMaps < ' tcx > {
240236 IrMaps {
241237 tcx,
242- body_owner,
243238 live_node_map : HirIdMap :: default ( ) ,
244239 variable_map : HirIdMap :: default ( ) ,
245240 capture_info_map : Default :: default ( ) ,
@@ -316,7 +311,7 @@ fn visit_fn<'tcx>(
316311
317312 // swap in a new set of IR maps for this function body:
318313 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 ) ;
320315
321316 // Don't run unused pass for #[derive()]
322317 if let FnKind :: Method ( ..) = fk {
@@ -448,10 +443,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
448443 } ) ) ;
449444 }
450445 ir. set_captures ( expr. hir_id , call_caps) ;
451- let old_body_owner = ir. body_owner ;
452- ir. body_owner = closure_def_id;
453446 intravisit:: walk_expr ( ir, expr) ;
454- ir. body_owner = old_body_owner;
455447 }
456448
457449 // live nodes required for interesting control flow:
@@ -605,6 +597,7 @@ const ACC_USE: u32 = 4;
605597
606598struct Liveness < ' a , ' tcx > {
607599 ir : & ' a mut IrMaps < ' tcx > ,
600+ body_owner : LocalDefId ,
608601 typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
609602 param_env : ty:: ParamEnv < ' tcx > ,
610603 successors : IndexVec < LiveNode , LiveNode > ,
@@ -626,9 +619,9 @@ struct Liveness<'a, 'tcx> {
626619}
627620
628621impl < ' 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 ) ;
632625
633626 let closure_ln = ir. add_live_node ( ClosureNode ) ;
634627 let exit_ln = ir. add_live_node ( ExitNode ) ;
@@ -638,6 +631,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
638631
639632 Liveness {
640633 ir,
634+ body_owner,
641635 typeck_results,
642636 param_env,
643637 successors : IndexVec :: from_elem_n ( INVALID_NODE , num_live_nodes) ,
@@ -893,12 +887,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
893887 // if they are live on the entry to the closure, since only the closure
894888 // itself can access them on subsequent calls.
895889
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 ) {
897891 // Mark upvars captured by reference as used after closure exits.
898892 for ( & var_hir_id, upvar) in upvars. iter ( ) . rev ( ) {
899893 let upvar_id = ty:: UpvarId {
900894 var_path : ty:: UpvarPath { hir_id : var_hir_id } ,
901- closure_expr_id : self . ir . body_owner ,
895+ closure_expr_id : self . body_owner ,
902896 } ;
903897 match self . typeck_results . upvar_capture ( upvar_id) {
904898 ty:: UpvarCapture :: ByRef ( _) => {
@@ -1565,15 +1559,15 @@ impl<'tcx> Liveness<'_, 'tcx> {
15651559 }
15661560
15671561 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 ) {
15691563 None => return ,
15701564 Some ( upvars) => upvars,
15711565 } ;
15721566 for ( & var_hir_id, upvar) in upvars. iter ( ) {
15731567 let var = self . variable ( var_hir_id, upvar. span ) ;
15741568 let upvar_id = ty:: UpvarId {
15751569 var_path : ty:: UpvarPath { hir_id : var_hir_id } ,
1576- closure_expr_id : self . ir . body_owner ,
1570+ closure_expr_id : self . body_owner ,
15771571 } ;
15781572 match self . typeck_results . upvar_capture ( upvar_id) {
15791573 ty:: UpvarCapture :: ByValue ( _) => { }
0 commit comments