Skip to content

unused_variables gives bad suggestion for nested struct pattern #88403

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
ehuss opened this issue Aug 27, 2021 · 0 comments · Fixed by #88871
Closed

unused_variables gives bad suggestion for nested struct pattern #88403

ehuss opened this issue Aug 27, 2021 · 0 comments · Fixed by #88871
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 27, 2021

I tried this code:

struct Foo {
    bar: Bar,
}

struct Bar {
    f1: i32,
}

fn main() {
    let f = Foo { bar: Bar { f1: 1 } };

    let Foo { bar: Bar { f1 } } = f;   // f1 is unused
}

This generates an unused_variables lint for the pattern. However, the suggestion it gives causes the code to fail to compile:

    let Foo { bar: Bar { _f1 } } = f;

I think it should give the same suggestion it gives for a non-nested binding, like this:

    let Foo { bar: Bar { f1: _ } } = f;

Found during crater run for https://github.com/Kylebrown9/Slang

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (b03ccace5 2021-08-24)
binary: rustc
commit-hash: b03ccace573bb91e27625c190a0f7807045a1012
commit-date: 2021-08-24
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0
@ehuss ehuss added C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Aug 27, 2021
@bors bors closed this as completed in 60b9c5d Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant