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

E0532 could perhaps chose better binding names? #106862

Closed
matthiaskrgr opened this issue Jan 14, 2023 · 1 comment · Fixed by #108971
Closed

E0532 could perhaps chose better binding names? #106862

matthiaskrgr opened this issue Jan 14, 2023 · 1 comment · Fixed by #108971
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 14, 2023

Given the following code:

use Foo::FooB;

enum Foo {
    FooB { x: i32, y: i32 }
}

fn main() {
    let f = FooB { x: 3, y: 4 };
    match f {
        FooB(a, b) => println!("{} {}", a, b),
        //~^ ERROR expected tuple struct or tuple variant, found variant `FooB`
    }
}

The current output is:

error[E0532]: expected tuple struct or tuple variant, found variant `FooB`
  --> src/main.rs:10:9
   |
4  |     FooB { x: i32, y: i32 }
   |     ----------------------- `FooB` defined here
...
10 |         FooB(a, b) => println!("{} {}", a, b),
   |         ^^^^^^^^^^ help: use struct pattern syntax instead: `FooB { x, y }`

Currently, this will fail to apply because we name the bindings x and y, but end up using a and b. I wonder if we can make the suggestion more clever to actually work around this so that this can be automatically applied.

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 14, 2023
@Ezrashaw
Copy link
Contributor

Ezrashaw commented Jan 15, 2023

Right, so name bindings according to the actual field names?

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 15, 2023
…s, r=WaffleLapkin

error-msg: impl better suggestion for `E0532`

Fixes rust-lang#106862

No test as there is already a test which is nearly identical to the example in the linked issue.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 16, 2023
…s, r=WaffleLapkin

error-msg: impl better suggestion for `E0532`

Fixes rust-lang#106862

No test as there is already a test which is nearly identical to the example in the linked issue.
@bors bors closed this as completed in 1385a32 Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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