Skip to content

Commit 536b51a

Browse files
committed
liveness: Store upvars_mentioned inside Liveness struct
1 parent b629ffd commit 536b51a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/rustc_passes/src/liveness.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ struct Liveness<'a, 'tcx> {
604604
body_owner: LocalDefId,
605605
typeck_results: &'a ty::TypeckResults<'tcx>,
606606
param_env: ty::ParamEnv<'tcx>,
607+
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
607608
successors: IndexVec<LiveNode, LiveNode>,
608609
rwu_table: RWUTable,
609610

@@ -626,6 +627,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
626627
fn new(ir: &'a mut IrMaps<'tcx>, body_owner: LocalDefId) -> Liveness<'a, 'tcx> {
627628
let typeck_results = ir.tcx.typeck(body_owner);
628629
let param_env = ir.tcx.param_env(body_owner);
630+
let upvars = ir.tcx.upvars_mentioned(body_owner);
629631

630632
let closure_ln = ir.add_live_node(ClosureNode);
631633
let exit_ln = ir.add_live_node(ExitNode);
@@ -638,6 +640,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
638640
body_owner,
639641
typeck_results,
640642
param_env,
643+
upvars,
641644
successors: IndexVec::from_elem_n(INVALID_NODE, num_live_nodes),
642645
rwu_table: RWUTable::new(num_live_nodes * num_vars),
643646
closure_ln,
@@ -885,8 +888,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
885888
// if they are live on the entry to the closure, since only the closure
886889
// itself can access them on subsequent calls.
887890

888-
let upvars = self.ir.tcx.upvars_mentioned(self.body_owner);
889-
if let Some(upvars) = upvars {
891+
if let Some(upvars) = self.upvars {
890892
// Mark upvars captured by reference as used after closure exits.
891893
for (&var_hir_id, upvar) in upvars.iter().rev() {
892894
let upvar_id = ty::UpvarId {
@@ -905,7 +907,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
905907

906908
let succ = self.propagate_through_expr(&body.value, self.exit_ln);
907909

908-
if upvars.is_none() {
910+
if self.upvars.is_none() {
909911
// Either not a closure, or closure without any captured variables.
910912
// No need to determine liveness of captured variables, since there
911913
// are none.
@@ -1560,7 +1562,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
15601562
}
15611563

15621564
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 {
15641566
None => return,
15651567
Some(upvars) => upvars,
15661568
};

0 commit comments

Comments
 (0)