Implement liveness passes for if-let guards
This commit is contained in:
parent
f9cc626028
commit
cfaaa21e2a
1 changed files with 10 additions and 4 deletions
|
@ -358,6 +358,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
||||||
|
|
||||||
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
|
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
|
||||||
self.add_from_pat(&arm.pat);
|
self.add_from_pat(&arm.pat);
|
||||||
|
if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
|
||||||
|
self.add_from_pat(pat);
|
||||||
|
}
|
||||||
intravisit::walk_arm(self, arm);
|
intravisit::walk_arm(self, arm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1029,10 +1032,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
let body_succ = self.propagate_through_expr(&arm.body, succ);
|
let body_succ = self.propagate_through_expr(&arm.body, succ);
|
||||||
|
|
||||||
let guard_succ = self.propagate_through_opt_expr(
|
let guard_succ = arm.guard.as_ref().map_or(body_succ, |g| match g {
|
||||||
arm.guard.as_ref().map(|hir::Guard::If(e)| *e),
|
hir::Guard::If(e) => self.propagate_through_expr(e, body_succ),
|
||||||
body_succ,
|
hir::Guard::IfLet(pat, e) => {
|
||||||
);
|
let let_bind = self.define_bindings_in_pat(pat, body_succ);
|
||||||
|
self.propagate_through_expr(e, let_bind)
|
||||||
|
}
|
||||||
|
});
|
||||||
let arm_succ = self.define_bindings_in_pat(&arm.pat, guard_succ);
|
let arm_succ = self.define_bindings_in_pat(&arm.pat, guard_succ);
|
||||||
self.merge_from_succ(ln, arm_succ, first_merge);
|
self.merge_from_succ(ln, arm_succ, first_merge);
|
||||||
first_merge = false;
|
first_merge = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue