Skip to content

Commit fdec5b6

Browse files
committed
Also walk bindings created by if-let guards
1 parent fb5ed72 commit fdec5b6

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

compiler/rustc_passes/src/liveness.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
13511351

13521352
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
13531353
self.check_unused_vars_in_pat(arm.pat, None, None, |_, _, _, _| {});
1354+
if let Some(hir::Guard::IfLet(let_expr)) = arm.guard {
1355+
self.check_unused_vars_in_pat(let_expr.pat, None, None, |_, _, _, _| {});
1356+
}
13541357
intravisit::walk_arm(self, arm);
13551358
}
13561359
}

tests/ui/lint/unused/issue-119383.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(if_let_guard)]
2+
#![deny(unused_variables)]
3+
4+
fn main() {
5+
match () {
6+
() if let Some(b) = Some(()) => {} //~ ERROR unused variable: `b`
7+
_ => {}
8+
}
9+
}
10+
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `b`
2+
--> $DIR/issue-119383.rs:6:24
3+
|
4+
LL | () if let Some(b) = Some(()) => {}
5+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-119383.rs:2:9
9+
|
10+
LL | #![deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)