Skip to content
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

Unify errors for Unit pattern on Tuple and Struct variants #63983

Closed
djrenren opened this issue Aug 28, 2019 · 4 comments · Fixed by #64660
Closed

Unify errors for Unit pattern on Tuple and Struct variants #63983

djrenren opened this issue Aug 28, 2019 · 4 comments · Fixed by #64660
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@djrenren
Copy link
Contributor

Code Example (playground):

enum MyEnum {
    Tuple(i32),
    Struct { s: i32 },
}

fn foo(en: MyEnum) {
    match en {
        MyEnum::Tuple => "",
        MyEnum::Struct => "",
    };
}

image

Currently we provide a "do you mean..." for the Struct but not for the Tuple. We probably should provide one for both.

@zackmdavis zackmdavis added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Aug 28, 2019
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2019
@Phosphorus15
Copy link
Contributor

Consider fixing #63988 Btw (which is a similar enhancement)

@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 29, 2019
@almielczarek
Copy link

I'd like to work on this if it is still available.

@estebank
Copy link
Contributor

@almielczarek go ahead!

Ideally, you could turn the output into

error[E0532]: expected unit struct/variant or constant, found tuple variant `MyEnum::Tuple`
 --> src/lib.rs:8:9
  |
8 |         MyEnum::Tuple => "",
  |         ^^^^^^^^^^^^^ help: missing arguments: `MyEnum::Tuple(_)`

error[E0532]: expected unit struct/variant or constant, found struct variant `MyEnum::Struct`
 --> src/lib.rs:9:9
  |
9 |         MyEnum::Struct => "",
  |         ^^^^^^^^^^^^^^ help: missing struct fields: `MyEnum::Struct { s }`

but just changing the tuple case would be enough.

@guanqun
Copy link
Contributor

guanqun commented Sep 21, 2019

@estebank I created a PR, could you please help review. I took a look at your suggestion of updating all the errors to help: missing struct fields.., that seemed too many changes, not sure if it was necessary, so I just added the tuple case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants