@@ -604,6 +604,7 @@ struct Liveness<'a, 'tcx> {
604
604
body_owner : LocalDefId ,
605
605
typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
606
606
param_env : ty:: ParamEnv < ' tcx > ,
607
+ upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
607
608
successors : IndexVec < LiveNode , LiveNode > ,
608
609
rwu_table : RWUTable ,
609
610
@@ -626,6 +627,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
626
627
fn new ( ir : & ' a mut IrMaps < ' tcx > , body_owner : LocalDefId ) -> Liveness < ' a , ' tcx > {
627
628
let typeck_results = ir. tcx . typeck ( body_owner) ;
628
629
let param_env = ir. tcx . param_env ( body_owner) ;
630
+ let upvars = ir. tcx . upvars_mentioned ( body_owner) ;
629
631
630
632
let closure_ln = ir. add_live_node ( ClosureNode ) ;
631
633
let exit_ln = ir. add_live_node ( ExitNode ) ;
@@ -638,6 +640,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
638
640
body_owner,
639
641
typeck_results,
640
642
param_env,
643
+ upvars,
641
644
successors : IndexVec :: from_elem_n ( INVALID_NODE , num_live_nodes) ,
642
645
rwu_table : RWUTable :: new ( num_live_nodes * num_vars) ,
643
646
closure_ln,
@@ -885,8 +888,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
885
888
// if they are live on the entry to the closure, since only the closure
886
889
// itself can access them on subsequent calls.
887
890
888
- let upvars = self . ir . tcx . upvars_mentioned ( self . body_owner ) ;
889
- if let Some ( upvars) = upvars {
891
+ if let Some ( upvars) = self . upvars {
890
892
// Mark upvars captured by reference as used after closure exits.
891
893
for ( & var_hir_id, upvar) in upvars. iter ( ) . rev ( ) {
892
894
let upvar_id = ty:: UpvarId {
@@ -905,7 +907,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
905
907
906
908
let succ = self . propagate_through_expr ( & body. value , self . exit_ln ) ;
907
909
908
- if upvars. is_none ( ) {
910
+ if self . upvars . is_none ( ) {
909
911
// Either not a closure, or closure without any captured variables.
910
912
// No need to determine liveness of captured variables, since there
911
913
// are none.
@@ -1560,7 +1562,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
1560
1562
}
1561
1563
1562
1564
fn warn_about_unused_upvars ( & self , entry_ln : LiveNode ) {
1563
- let upvars = match self . ir . tcx . upvars_mentioned ( self . body_owner ) {
1565
+ let upvars = match self . upvars {
1564
1566
None => return ,
1565
1567
Some ( upvars) => upvars,
1566
1568
} ;
0 commit comments