Skip to content

Incorrect non-exhaustive pattern error #72476

Closed
@tmiasko

Description

@tmiasko
enum Next<I> where I: Iterator {
    Item(I::Item),
}

fn e(item: Next<&mut dyn Iterator<Item=Option<()>>>) {
    match item {
        Next::Item(None) => {}
        Next::Item(Some(())) => {}
    }
}

fn main() {}

Produces non-exhaustive pattern error (even though all patterns are covered):

error[E0004]: non-exhaustive patterns: `Item(_)` not covered
 --> main.rs:6:11
  |
1 | / enum Next<I> where I: Iterator {
2 | |     Item(I::Item),
  | |     ---- not covered
3 | | }
  | |_- `Next<&mut dyn std::iter::Iterator<Item = std::option::Option<()>>>` defined here
...
6 |       match item {
  |             ^^^^ pattern `Item(_)` 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 `Next<&mut dyn std::iter::Iterator<Item = std::option::Option<()>>>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0004`.

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (9310e3bd4 2020-05-21)
binary: rustc
commit-hash: 9310e3bd4f425f84fc27878ebf2bda1f30935a63
commit-date: 2020-05-21
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions