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

Vector pattern exhaustiveness #13482

Closed
Boddlnagg opened this issue Apr 12, 2014 · 1 comment
Closed

Vector pattern exhaustiveness #13482

Boddlnagg opened this issue Apr 12, 2014 · 1 comment

Comments

@Boddlnagg
Copy link
Contributor

Compiling the following code (with current master) results in "error: non-exhaustive patterns: vectors of length 2 not covered". I don't know if this ought to be valid, but at least the error-message is wrong, because obviously there is a match-branch for vectors of length 2.

fn main() {
  let x = [1,2];
  let y = match x {
    [] => None,
    [a,_] => Some(a)
  };
  println!("{}", y);            
}
@ghost
Copy link

ghost commented Apr 15, 2014

The variable x is an array with a static length of 2 (in Rust's syntax it would be [T, ..2]), whereas the first pattern has type [T, ..0]. It wouldn't make much sense for it to be valid. The error message is indeed incorrect, however. I believe the type error is making it past the type checker before it gets to the match checker, which is the culprit for creating that very confusing error message. I'm new to the Rust compiler, though, so I'm not sure on that last part.

Nice find! If this is still open tomorrow I'll take a look at it more thoroughly.

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

1 participant