Skip to content
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

allow(unused_variables) doesn't work on struct field bindings in patterns #138428

Closed
camsteffen opened this issue Mar 12, 2025 · 0 comments · Fixed by #138434
Closed

allow(unused_variables) doesn't work on struct field bindings in patterns #138428

camsteffen opened this issue Mar 12, 2025 · 0 comments · Fixed by #138434
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camsteffen
Copy link
Contributor

I tried this code:

pub struct Foo {
    bar: u32,
    baz: u32,
}

pub fn test(foo: Foo) {
    let Foo {
        #[allow(unused_variables)]
        bar,
        #[allow(unused_variables)]
        baz,
    } = foo;
}

I expected to see this happen:

no lint

Instead, this happened:

unused_variables lint occurs even though it is allowed

Meta

rustc version 1.85.0

Playground

@camsteffen camsteffen added the C-bug Category: This is a bug. label Mar 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 12, 2025
@fmease fmease changed the title allow(unused_variables) doesn't work on struct field in this case allow(unused_variables) doesn't work on struct field bindings in patterns Mar 12, 2025
@compiler-errors compiler-errors self-assigned this Mar 13, 2025
@jieyouxu jieyouxu 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. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 13, 2025
@fmease fmease added L-unused_variables Lint: unused_variables A-patterns Relating to patterns and pattern matching and removed L-unused_variables Lint: unused_variables labels Mar 13, 2025
@bors bors closed this as completed in fb2a7fa Mar 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 14, 2025
Rollup merge of rust-lang#138434 - compiler-errors:lint-level-pat-field, r=jieyouxu

Visit `PatField` when collecting lint levels

Fixes rust-lang#138428

Side-note, I vaguely skimmed over the other nodes we could be visiting here and it doesn't *seem* to me that we're missing anything, though I may be mistaken given recent(?) support for attrs in where clauses(??). Can be fixed in a follow-up PR.
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. A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. 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.

5 participants