-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #95396 - TaKO8Ki:suggest-replacing-field-when-using-the…
…-same-type, r=compiler-errors Suggest replacing a field when using the same type closes #89166
- Loading branch information
Showing
3 changed files
with
159 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
enum Foo { | ||
Bar { a: u8, b: i8, c: u8 }, | ||
Baz { a: f32 }, | ||
None, | ||
} | ||
|
||
fn main() { | ||
let foo = Foo::None; | ||
match foo { | ||
Foo::Bar { a, aa: 1, c } => (), | ||
//~^ ERROR variant `Foo::Bar` does not have a field named `aa` [E0026] | ||
//~| ERROR pattern does not mention field `b` [E0027] | ||
Foo::Baz { bb: 1.0 } => (), | ||
//~^ ERROR variant `Foo::Baz` does not have a field named `bb` [E0026] | ||
//~| ERROR pattern does not mention field `a` [E0027] | ||
_ => (), | ||
} | ||
|
||
match foo { | ||
Foo::Bar { a, aa: "", c } => (), | ||
//~^ ERROR variant `Foo::Bar` does not have a field named `aa` [E0026] | ||
//~| ERROR pattern does not mention field `b` [E0027] | ||
Foo::Baz { bb: "" } => (), | ||
//~^ ERROR variant `Foo::Baz` does not have a field named `bb` [E0026] | ||
//~| pattern does not mention field `a` [E0027] | ||
_ => (), | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
error[E0026]: variant `Foo::Bar` does not have a field named `aa` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:10:23 | ||
| | ||
LL | Foo::Bar { a, aa: 1, c } => (), | ||
| ^^ | ||
| | | ||
| variant `Foo::Bar` does not have this field | ||
| help: `Foo::Bar` has a field named `b` | ||
|
||
error[E0027]: pattern does not mention field `b` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:10:9 | ||
| | ||
LL | Foo::Bar { a, aa: 1, c } => (), | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing field `b` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | Foo::Bar { a, aa: 1, c, b } => (), | ||
| ~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | Foo::Bar { a, aa: 1, c, .. } => (), | ||
| ~~~~~~ | ||
|
||
error[E0026]: variant `Foo::Baz` does not have a field named `bb` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:13:20 | ||
| | ||
LL | Foo::Baz { bb: 1.0 } => (), | ||
| ^^ | ||
| | | ||
| variant `Foo::Baz` does not have this field | ||
| help: `Foo::Baz` has a field named `a` | ||
|
||
error[E0027]: pattern does not mention field `a` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:13:9 | ||
| | ||
LL | Foo::Baz { bb: 1.0 } => (), | ||
| ^^^^^^^^^^^^^^^^^^^^ missing field `a` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | Foo::Baz { bb: 1.0, a } => (), | ||
| ~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | Foo::Baz { bb: 1.0, .. } => (), | ||
| ~~~~~~ | ||
|
||
error[E0026]: variant `Foo::Bar` does not have a field named `aa` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:20:23 | ||
| | ||
LL | Foo::Bar { a, aa: "", c } => (), | ||
| ^^ variant `Foo::Bar` does not have this field | ||
|
||
error[E0027]: pattern does not mention field `b` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:20:9 | ||
| | ||
LL | Foo::Bar { a, aa: "", c } => (), | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `b` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | Foo::Bar { a, aa: "", c, b } => (), | ||
| ~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | Foo::Bar { a, aa: "", c, .. } => (), | ||
| ~~~~~~ | ||
|
||
error[E0026]: variant `Foo::Baz` does not have a field named `bb` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:23:20 | ||
| | ||
LL | Foo::Baz { bb: "" } => (), | ||
| ^^ variant `Foo::Baz` does not have this field | ||
|
||
error[E0027]: pattern does not mention field `a` | ||
--> $DIR/suggest-replacing-field-when-specifying-same-type.rs:23:9 | ||
| | ||
LL | Foo::Baz { bb: "" } => (), | ||
| ^^^^^^^^^^^^^^^^^^^ missing field `a` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | Foo::Baz { bb: "", a } => (), | ||
| ~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | Foo::Baz { bb: "", .. } => (), | ||
| ~~~~~~ | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0026, E0027. | ||
For more information about an error, try `rustc --explain E0026`. |