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

E0004 lists incorrect secondary witnesses #36410

Closed
jfirebaugh opened this issue Sep 12, 2016 · 3 comments
Closed

E0004 lists incorrect secondary witnesses #36410

jfirebaugh opened this issue Sep 12, 2016 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@jfirebaugh
Copy link
Contributor

#31020 added display of multiple witnesses to the error message for non-exhaustive match patterns. However, witnesses beyond the first one may have inappropriate types. For example:

enum Direction {
    North,
    East,
    South,
    West,
}

fn main() {
    match Some(Direction::North) {
        Some(Direction::North) => (),
        None => ()
    }
}

Output:

error[E0004]: non-exhaustive patterns: `Some(East)`, `South` and `West` not covered
 --> <anon>:9:11
  |
9 |     match Some(Direction::North) {
  |           ^^^^^^^^^^^^^^^^^^^^^^ patterns `Some(East)`, `South` and `West` not covered

error: aborting due to previous error

Here, "South and West not covered" should read "Some(South) and Some(West) not covered".

@TimNN
Copy link
Contributor

TimNN commented Sep 12, 2016

Duplicate of / related to #35609, I think.

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 13, 2016
@Cobrand
Copy link
Contributor

Cobrand commented Sep 16, 2016

Ok, so I tried to "fix" this issue to dirty my hands a little with the rust compiler, thinking that it would be easy, cause it was probably a very simple issue to fix. How wrong I was. This is simply not a bug of my level, I'm sorry; but I'll try to explain what I've understood while investigating.

This issue is actually quite messed up, here is some code that might make you understand : https://play.rust-lang.org/?gist=5ca5977ed3c44048518e808e8d821bb8&version=nightly&backtrace=0

So what would we expect in that case ? Certainly not
patterns Double(Chocolate, Pistachio)andStrawberry not covered. It makes no sense.

This problem comes actually from here : https://github.com/rust-lang/rust/blob/master/src/librustc_const_eval/check_match.rs#L726-L735

Number of patterns left and arity are mixed together, in this code. Guess what happens If you have an enum where the number of fields possible is greater than the number of variants in the enum ?
This happens :
https://play.rust-lang.org/?gist=863ccc9cecc4932a28532011127f7d40&version=nightly&backtrace=0

That's right, it just displays "_" for the fields that can't be "bound" to a variant.

Now you might be wondering, but if the arity and the number of patterns left are mixed together, what happens if you mix different enums in the patterns ? I'll show you what happens 👍

https://play.rust-lang.org/?gist=3175b98130b9ba03bd9f2f6d85631a16&version=nightly&backtrace=0

We should at least see a mention of the other enum in this code, but we don't. Again, this makes absolutely no sense at all, but I'd say this behavior is "expected" from the bug.

Now I think I'm going to leave this issue as it is, cause this is probably way out of my league for newcomer like myself :( .

@arielb1
Copy link
Contributor

arielb1 commented Sep 24, 2016

duplicate of #35609.

@arielb1 arielb1 closed this as completed Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

5 participants