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

non-exhaustive pattern error should mention existence of #[non_exhaustive] attribute #85227

Closed
zesterer opened this issue May 12, 2021 · 0 comments · Fixed by #85233
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zesterer
Copy link
Contributor

The error message when matching exhaustively on a non-exhaustive enum is as follows:

error[E0004]: non-exhaustive patterns: `_` not covered
   --> main.rs:123:15
    |
123 |         match output {
    |               ^^^^^^ pattern `_` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `Foo`

error: aborting due to previous error

(note that this error only occurs when the enum is defined in another crate and with the #[non_exhaustive] attribute)

Ideally the output should look like:

error[E0004]: non-exhaustive patterns: possible future patterns not covered
   --> main.rs:123:15
    |
123 |         match output {
    |               ^^^^^^ pattern `_` not covered
    |
    = help: ensure that all future cases are being handled, possibly by adding a wildcard
    = note: the type of the matched value is marked `non_exhaustive`

error: aborting due to previous error

It's often easy to miss the non_exhaustive attribute (both in the docs and when reading source code with a lot of type attributes), leading to confusion. I was personally caught by this, and I think it would be useful if the compiler was able to communicate to the user the true cause of the issue.

@zesterer zesterer added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 12, 2021
@bors bors closed this as completed in 69b352e May 14, 2021
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 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.

1 participant