Skip to content

Unused variables inside if-let guards don't get detected #119383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fmease opened this issue Dec 28, 2023 · 0 comments · Fixed by #119402
Closed

Unused variables inside if-let guards don't get detected #119383

fmease opened this issue Dec 28, 2023 · 0 comments · Fixed by #119402
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-if_let_guard `#![feature(if_let_guard)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Dec 28, 2023

I expected the following code to fail to compile due to the unused variable unused but it actually compiled successfully:

#![feature(if_let_guard)]
#![deny(unused_variables)]

fn main() {
    match () {
        () if let Some(unused) = Some(()) => {}
        _ => {}
    }
}
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. F-if_let_guard `#![feature(if_let_guard)]` labels Dec 28, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 28, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 28, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 29, 2023
…ler-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
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 29, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-if_let_guard `#![feature(if_let_guard)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants