Closed
Description
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.