Skip to content

Exhaustiveness checker errors on unconstructible enum variant #69696

Closed
@matprec

Description

@matprec
use std::marker::PhantomData;

enum Void {}

enum Foo<T=()> {
    Bar,
    Baz,
    Phantom(PhantomData<T>, Void)
}

pub fn test(f: Foo) {
    match f {
        Foo::Bar => println!("Bar"),
        Foo::Baz => println!("Baz"),
    }
}

Playground

I expect this to work, since the Phantom case is not constructible, since it contains a Void type.

The exhaustiveness checker instead errors because it thinks that the Phantom case should be covered as well:

error[E0004]: non-exhaustive patterns: `Phantom(_, _)` not covered
  --> src/lib.rs:12:11
   |
5  | / enum Foo<T=()> {
6  | |     Bar,
7  | |     Baz,
8  | |     Phantom(PhantomData<T>, Void)
   | |     ------- not covered
9  | | }
   | |_- `Foo` defined here
...
12 |       match f {
   |             ^ pattern `Phantom(_, _)` not covered
   |
   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

error: aborting due to previous error

Meta

Happens on stable and nightly as of 2020-03-04

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions