mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #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 #119383
This commit is contained in:
commit
efd9fd66ba
@ -1328,6 +1328,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);
|
||||
}
|
||||
}
|
||||
|
9
tests/ui/lint/unused/issue-119383.rs
Normal file
9
tests/ui/lint/unused/issue-119383.rs
Normal file
@ -0,0 +1,9 @@
|
||||
#![feature(if_let_guard)]
|
||||
#![deny(unused_variables)]
|
||||
|
||||
fn main() {
|
||||
match () {
|
||||
() if let Some(b) = Some(()) => {} //~ ERROR unused variable: `b`
|
||||
_ => {}
|
||||
}
|
||||
}
|
14
tests/ui/lint/unused/issue-119383.stderr
Normal file
14
tests/ui/lint/unused/issue-119383.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user