Skip to content

Commit

Permalink
Also walk bindings created by if-let guards
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Dec 29, 2023
1 parent fb5ed72 commit ab60a7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,9 @@ 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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/lint/unused/issue-119383.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(if_let_guard)]
#![deny(unused_variables)]

fn main() {
match () {
() if let Some(b) = Some(()) => {} //~ ERROR unused variable: `b`
_ => {}
}
}
14 changes: 14 additions & 0 deletions tests/ui/lint/unused/issue-119383.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unused variable: `b`
--> $DIR/issue-119383.rs:6:24
|
LL | () if let Some(b) = Some(()) => {}
| ^ help: if this is intentional, prefix it with an underscore: `_b`
|
note: the lint level is defined here
--> $DIR/issue-119383.rs:2:9
|
LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

0 comments on commit ab60a7d

Please sign in to comment.