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

Confusing unreachable pattern error #31221

Closed
pyfisch opened this issue Jan 26, 2016 · 5 comments
Closed

Confusing unreachable pattern error #31221

pyfisch opened this issue Jan 26, 2016 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@pyfisch
Copy link
Contributor

pyfisch commented Jan 26, 2016

This simple code fails to compile because Other is not defined. But the error message is unreachable pattern [E0001] Bar => "bar". But Bar is not the cause it just happens to occur after Other.

enum Foobar {
    Foo,
    Bar,
}

fn main() {
    use Foobar::*;
    let x = Foo;
    println!("{}", match x {
        Foo => "foo",
        Other => "other",
        Bar => "bar",
    });
}

http://is.gd/zL6HGt

@apasel422
Copy link
Contributor

I agree that this is confusing, though from the compiler's perspective, the error message makes sense. Since Other isn't a variant of Foobar, Other becomes the name of a binding that matches all possible values of x other than Foobar::Foo. (See https://doc.rust-lang.org/book/patterns.html.) Once that happens, the Bar case is indeed unreachable.

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

Perhaps the error message could point to the match arm that the unreachable arm overlaps with.

@durka
Copy link
Contributor

durka commented Jan 26, 2016

Also if you comment out the Bar arm, you get a snake-case warning on Other, but unfortunately the error happens first.

@pyfisch
Copy link
Contributor Author

pyfisch commented Jan 26, 2016

Thanks for your coments. Now at least I understand why the compiler printed this error message.

@nagisa
Copy link
Member

nagisa commented Jan 27, 2016

Related: #5657

birkenfeld added a commit to birkenfeld/rust that referenced this issue May 1, 2016
Caught as catchall patterns are:

* unconditional name bindings
* references to them
* tuple bindings with catchall elements

Fixes rust-lang#31221.
Manishearth added a commit to Manishearth/rust that referenced this issue May 2, 2016
match check: note "catchall" patterns in unreachable error

Caught as catchall patterns are:

* unconditional name bindings
* references to them
* tuple bindings with catchall elements

Fixes rust-lang#31221.
Manishearth added a commit to Manishearth/rust that referenced this issue May 3, 2016
match check: note "catchall" patterns in unreachable error

Caught as catchall patterns are:

* unconditional name bindings
* references to them
* tuple bindings with catchall elements

Fixes rust-lang#31221.
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

4 participants