1
Fork 0

Rollup merge of #119554 - matthewjasper:remove-guard-distinction, r=compiler-errors

Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes #118593
This commit is contained in:
Matthias Krüger 2024-01-05 20:39:52 +01:00 committed by GitHub
commit 958417fba1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 272 additions and 292 deletions

View file

@ -351,10 +351,7 @@ 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(let_expr)) = arm.guard {
self.add_from_pat(let_expr.pat);
}
self.add_from_pat(&arm.pat);
intravisit::walk_arm(self, arm);
}
@ -921,14 +918,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
for arm in arms {
let body_succ = self.propagate_through_expr(arm.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(let_expr) => {
let let_bind = self.define_bindings_in_pat(let_expr.pat, body_succ);
self.propagate_through_expr(let_expr.init, let_bind)
}
});
let arm_succ = self.define_bindings_in_pat(arm.pat, guard_succ);
let guard_succ = arm
.guard
.as_ref()
.map_or(body_succ, |g| self.propagate_through_expr(g, body_succ));
let arm_succ = self.define_bindings_in_pat(&arm.pat, guard_succ);
self.merge_from_succ(ln, arm_succ);
}
self.propagate_through_expr(e, ln)
@ -1328,9 +1322,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
self.check_unused_vars_in_pat(arm.pat, None, None, |_, _, _, _| {});
if let Some(hir::Guard::IfLet(let_expr)) = arm.guard {
self.check_unused_vars_in_pat(let_expr.pat, None, None, |_, _, _, _| {});
}
intravisit::walk_arm(self, arm);
}
}