Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cfaaa21

Browse files
Implement liveness passes for if-let guards
1 parent f9cc626 commit cfaaa21

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

compiler/rustc_passes/src/liveness.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
358358

359359
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
360360
self.add_from_pat(&arm.pat);
361+
if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
362+
self.add_from_pat(pat);
363+
}
361364
intravisit::walk_arm(self, arm);
362365
}
363366

@@ -1029,10 +1032,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10291032
for arm in arms {
10301033
let body_succ = self.propagate_through_expr(&arm.body, succ);
10311034

1032-
let guard_succ = self.propagate_through_opt_expr(
1033-
arm.guard.as_ref().map(|hir::Guard::If(e)| *e),
1034-
body_succ,
1035-
);
1035+
let guard_succ = arm.guard.as_ref().map_or(body_succ, |g| match g {
1036+
hir::Guard::If(e) => self.propagate_through_expr(e, body_succ),
1037+
hir::Guard::IfLet(pat, e) => {
1038+
let let_bind = self.define_bindings_in_pat(pat, body_succ);
1039+
self.propagate_through_expr(e, let_bind)
1040+
}
1041+
});
10361042
let arm_succ = self.define_bindings_in_pat(&arm.pat, guard_succ);
10371043
self.merge_from_succ(ln, arm_succ, first_merge);
10381044
first_merge = false;

0 commit comments

Comments
 (0)