Skip to content

Commit efd9fd6

Browse files
authored
Rollup merge of rust-lang#119402 - est31:fix_if_guard_unused, r=compiler-errors
Also walk bindings created by if-let guards This change makes the `unused_variables` lint pick up unused bindings created by if-let guards. Fixes rust-lang#119383
2 parents 4b9a76c + ab60a7d commit efd9fd6

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

compiler/rustc_passes/src/liveness.rs

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

13291329
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
13301330
self.check_unused_vars_in_pat(arm.pat, None, None, |_, _, _, _| {});
1331+
if let Some(hir::Guard::IfLet(let_expr)) = arm.guard {
1332+
self.check_unused_vars_in_pat(let_expr.pat, None, None, |_, _, _, _| {});
1333+
}
13311334
intravisit::walk_arm(self, arm);
13321335
}
13331336
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
+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)