-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Suggest replacing a field when using the same type #95396
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
Merged
bors
merged 2 commits into
rust-lang:master
from
TaKO8Ki:suggest-replacing-field-when-using-the-same-type
Mar 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 hidden or 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 hidden or 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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.