Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for non-exhaustive patterns on tuples with an enum fills in all tuple components with successive enum values #35609

Closed
joshtriplett opened this issue Aug 11, 2016 · 1 comment

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Aug 11, 2016

I can reproduce this in both stable and nightly. Minimal test case:

enum Enum {
    A, B, C, D, E, F
}
use Enum::*;

fn main() {
    match (A, ()) {
        (A, _) => {}
    }
}

Error message from nightly:

error[E0004]: non-exhaustive patterns: `(B, C)`, `D`, `E` and 1 more not covered
 --> <anon>:7:5
  |
7 |     match (A, ()) {
  |     ^^^^^^^^^^^^^ patterns `(B, C)`, `D`, `E` and 1 more not covered

The error from stable looks similar, just with a different template:

error: non-exhaustive patterns: `(B, C)`, `D`, `E` and 1 more not covered [--explain E0004]
 --> <anon>:7:5
7 |>     match (A, ()) {
  |>     ^

If the matched item uses a different tuple nesting structure, the error message will fill in all the components of that structure with the enum values:

enum Enum {
    A, B, C, D, E, F
}
use Enum::*;

fn main() {
    match ((A, ()), ()) {
        ((A, ()), _) => {}
    }
}
error[E0004]: non-exhaustive patterns: `((B, C), D)`, `E` and `F` not covered
 --> <anon>:7:5
  |
7 |     match ((A, ()), ()) {
  |     ^^^^^^^^^^^^^^^^^^^ patterns `((B, C), D)`, `E` and `F` not covered

If the number of slots to fill in in the tuple structure exceeds the number of un-handled enum variants, the error message will use _ for the remaining slots:

enum Enum {
    A, B, C
}
use Enum::*;

fn main() {
    match ((A, ()), ()) {
        ((A, _), _) => {}
    }
}
error[E0004]: non-exhaustive patterns: `((B, C), _)` not covered
 --> <anon>:7:5
  |
7 |     match ((A, ()), ()) {
  |     ^^^^^^^^^^^^^^^^^^^ pattern `((B, C), _)` not covered

Edit: this also occurs with tuple structs:

enum Enum {
    A, B, C, D, E, F
}
use Enum::*;
struct S(Enum, ());

fn main() {
    match S(A, ()) {
        S(A, _) => {}
    }
}
error[E0004]: non-exhaustive patterns: `S(B, C)`, `D`, `E` and 1 more not covered
 --> <anon>:8:5
  |
8 |     match S(A, ()) {
  |     ^^^^^^^^^^^^^^ patterns `S(B, C)`, `D`, `E` and 1 more not covered

And with structs:

enum Enum {
    A, B, C, D, E, F
}
use Enum::*;
struct S { x: Enum, y: () }

fn main() {
    match (S { x: A, y: () }) {
        S { x: A, y: _ } => {}
    }
}
error[E0004]: non-exhaustive patterns: `S { x: B, y: C }`, `D`, `E` and 1 more not covered
 --> <anon>:8:5
  |
8 |     match (S { x: A, y: () }) {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^ patterns `S { x: B, y: C }`, `D`, `E` and 1 more not covered
@nagisa
Copy link
Member

nagisa commented Aug 21, 2016

Similarly with enums:

enum A { Outer(B) }
enum B { Inner1, Inner2, Inner3, }
fn main() { match A::Outer(B::Inner1) {A::Outer(B::Inner1) => {}} }
error: non-exhaustive patterns: `Outer(Inner2)` and `Inner3` not covered [--explain E0004]
  --> <anon>:11:5
   |>
11 |>     match A::Outer(B::Inner1) {A::Outer(B::Inner1) => {}}
   |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants