-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
resolve: improve "try using the enum's variant" #77341
Merged
bors
merged 1 commit into
rust-lang:master
from
davidtwco:issue-73427-you-might-have-meant-variant
Oct 7, 2020
Merged
Changes from all commits
Commits
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 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 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 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,44 @@ | ||
enum A { | ||
StructWithFields { x: () }, | ||
TupleWithFields(()), | ||
Struct {}, | ||
Tuple(), | ||
Unit, | ||
} | ||
|
||
enum B { | ||
StructWithFields { x: () }, | ||
TupleWithFields(()), | ||
} | ||
|
||
enum C { | ||
StructWithFields { x: () }, | ||
TupleWithFields(()), | ||
Unit, | ||
} | ||
|
||
enum D { | ||
TupleWithFields(()), | ||
Unit, | ||
} | ||
|
||
fn main() { | ||
// Only variants without fields are suggested (and others mentioned in a note) where an enum | ||
// is used rather than a variant. | ||
|
||
A.foo(); | ||
//~^ ERROR expected value, found enum `A` | ||
B.foo(); | ||
//~^ ERROR expected value, found enum `B` | ||
C.foo(); | ||
//~^ ERROR expected value, found enum `C` | ||
D.foo(); | ||
//~^ ERROR expected value, found enum `D` | ||
|
||
// Only tuple variants are suggested in calls or tuple struct pattern matching. | ||
|
||
let x = A(3); | ||
//~^ ERROR expected function, tuple struct or tuple variant, found enum `A` | ||
if let A(3) = x { } | ||
//~^ ERROR expected tuple struct or tuple variant, found enum `A` | ||
} |
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,72 @@ | ||
error[E0423]: expected value, found enum `A` | ||
--> $DIR/issue-73427.rs:29:5 | ||
| | ||
LL | A.foo(); | ||
| ^ | ||
| | ||
= help: you might have meant to use one of the enum's other variants that have fields | ||
help: try using one of the enum's variants | ||
| | ||
LL | (A::Struct {}).foo(); | ||
| ^^^^^^^^^^^^^^ | ||
LL | (A::Tuple()).foo(); | ||
| ^^^^^^^^^^^^ | ||
LL | A::Unit.foo(); | ||
| ^^^^^^^ | ||
|
||
error[E0423]: expected value, found enum `B` | ||
--> $DIR/issue-73427.rs:31:5 | ||
| | ||
LL | B.foo(); | ||
| ^ | ||
| | ||
= help: you might have meant to use one of the enum's variants | ||
|
||
error[E0423]: expected value, found enum `C` | ||
--> $DIR/issue-73427.rs:33:5 | ||
| | ||
LL | C.foo(); | ||
| ^ help: try using one of the enum's variants: `C::Unit` | ||
| | ||
= help: you might have meant to use one of the enum's other variants that have fields | ||
|
||
error[E0423]: expected value, found enum `D` | ||
--> $DIR/issue-73427.rs:35:5 | ||
| | ||
LL | D.foo(); | ||
| ^ help: try using one of the enum's variants: `D::Unit` | ||
| | ||
= help: you might have meant to use the enum's other variant that has fields | ||
|
||
error[E0423]: expected function, tuple struct or tuple variant, found enum `A` | ||
--> $DIR/issue-73427.rs:40:13 | ||
| | ||
LL | let x = A(3); | ||
| ^ | ||
| | ||
= help: you might have meant to construct one of the enum's non-tuple variants | ||
help: try using one of the enum's variants | ||
| | ||
LL | let x = A::TupleWithFields(3); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
LL | let x = A::Tuple(3); | ||
| ^^^^^^^^ | ||
|
||
error[E0532]: expected tuple struct or tuple variant, found enum `A` | ||
--> $DIR/issue-73427.rs:42:12 | ||
| | ||
LL | if let A(3) = x { } | ||
| ^ | ||
| | ||
= help: you might have meant to match against one of the enum's non-tuple variants | ||
help: try using one of the enum's variants | ||
| | ||
LL | if let A::TupleWithFields(3) = x { } | ||
| ^^^^^^^^^^^^^^^^^^ | ||
LL | if let A::Tuple(3) = x { } | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0423, E0532. | ||
For more information about an error, try `rustc --explain E0423`. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this to somehow suggest the non-tuple variants with placeholders. It would also mean getting the full span, if I'm reading correctly.