Skip to content

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

Closed
@zesterer

Description

@zesterer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions