mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Implement liveness passes for if-let guards
This commit is contained in:
parent
f9cc626028
commit
cfaaa21e2a
@ -358,6 +358,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
||||
|
||||
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1029,10 +1032,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
for arm in arms {
|
||||
let body_succ = self.propagate_through_expr(&arm.body, succ);
|
||||
|
||||
let guard_succ = self.propagate_through_opt_expr(
|
||||
arm.guard.as_ref().map(|hir::Guard::If(e)| *e),
|
||||
body_succ,
|
||||
);
|
||||
let guard_succ = arm.guard.as_ref().map_or(body_succ, |g| match g {
|
||||
hir::Guard::If(e) => self.propagate_through_expr(e, 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);
|
||||
self.merge_from_succ(ln, arm_succ, first_merge);
|
||||
first_merge = false;
|
||||
|
Loading…
Reference in New Issue
Block a user