Skip to content

E0532 could perhaps chose better binding names? #106862

Closed
@matthiaskrgr

Description

@matthiaskrgr

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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions