Skip to content

Message reporting missing patterns for inexhaustive match is misleading #72377

Closed

Description

@vandenheuvel

A small demo:

#[derive(PartialEq, Eq, Clone, Copy)]
enum X { A, B, C, }

fn main() {
  match (X::A, Some(X::A)) {
    (_, None) => false,
    (v, Some(w)) if v == w => true,
    (X::B, Some(X::C)) => false,
    (X::B, Some(X::A)) => false,
    (X::A, Some(X::C)) | (X::C, Some(X::A)) => false,
  };
}

Playground.

I expected to see this happen
The usual error message indicating that patterns (A, Some(B)) and (C, Some(B)) are not covered.

Instead, this happened
Patterns (A, Some(A)) and (A, Some(B)) are detected as not covered.

rustc --version --verbose:

rustc 1.45.0-nightly (a74d1862d 2020-05-14)
binary: rustc
commit-hash: a74d1862d4d87a56244958416fd05976c58ca1a8
commit-date: 2020-05-14
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

Activity

  1. jonas-schievink commented on May 20, 2020

    @jonas-schievink
    Contributor

    If you add the suggested arms, it will in fact detect the other ones as missing. It is expected that (A, Some(A)) is detected as not covered since the match guard is not taken into account when checking exhaustiveness (and couldn't be, since it's an arbitrary expression).

  2. jonas-schievink commented on May 21, 2020

    @jonas-schievink
    Contributor

    Closing as expected behavior.

  3. vandenheuvel commented on May 22, 2020

    @vandenheuvel
    ContributorAuthor

    It is expected that (A, Some(A)) is detected as not covered since the match guard is not taken into account when checking exhaustiveness

    Wouldn't you then expect that it mentions (A, Some(A)), (B, Some(B)), (C, Some(C)), (A, Some(B)) and (C, Some(B)) as not covered? Or is the number of outputs always restricted to two? In that case, I think it would be useful to indicate that some patterns might be missing, e.g.:

    error[E0004]: non-exhaustive patterns: at least `(A, Some(A))` and `(A, Some(B))` not covered
    
  4. jonas-schievink commented on May 22, 2020

    @jonas-schievink
    Contributor

    Yeah that's true

  5. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    C-bugCategory: This is a bug.
    on May 22, 2020
  6. changed the title [-]Wrong match pattern is detected as not covered[/-] [+]Message reporting missing patterns for inexhaustive match is misleading[/+] on May 30, 2020
  7. added 2 commits that reference this issue on Feb 15, 2021
    377a3ef
    3f160c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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