Closed
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2c9af7b21295b19d151a109261981cd2
enum Foo {
Bar { alpha: u8, bravo: u8, charlie: u8 },
}
fn foo(foo: Foo) {
match foo {
Foo::Bar {
alpha,
beta, // `bravo` miswritten as `beta` here.
charlie,
} => todo!(),
}
}
The current output is:
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
--> src/lib.rs:9:13
|
9 | beta, // `bravo` miswritten as `beta` here.
| ^^^^ variant `Foo::Bar` does not have this field
error[E0027]: pattern does not mention field `bravo`
--> src/lib.rs:7:9
|
7 | / Foo::Bar {
8 | | alpha,
9 | | beta, // `bravo` miswritten as `beta` here.
10 | | charlie,
11 | | } => todo!(),
| |_________^ missing field `bravo`
|
help: include the missing field in the pattern
|
10 | charlie, bravo } => todo!(),
| ^^^^^^^^^
help: if you don't care about this missing field, you can explicitly ignore it
|
10 | charlie, .. } => todo!(),
| ^^^^^^
error: aborting due to 2 previous errors
Ideally the output should look like:
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
--> src/lib.rs:9:13
|
9 | beta, // `bravo` miswritten as `beta` here.
| ^^^^ help: maybe replacing this for a missing field: `bravo`
We already provide a suggestion for similar names, for example, brav0
is suggested to replace it for bravo
.
Analogous to that, when the rest of the field (alpha
& charlie
) is mentioned, suggesting to replace the miswritten field (beta
) for the missing field (bravo
) can be helpful for users.