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

match statements that cover all possible values for type not seen as exhaustive #28477

Closed
carloslbello opened this issue Sep 17, 2015 · 2 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@carloslbello
Copy link
Contributor

Apologies if this is a dupe.

This doesn't compile:

fn main() {
    match 25u8 {
        0 ... 24 => println!("less than 25"),
        25 => println!("exactly 25"),
        26 ... 255 => println!("above 25")
    }
}

Error message:

<anon>:2:5: 6:6 error: non-exhaustive patterns: `_` not covered [E0004]
<anon>:2     match 25u8 {
<anon>:3         0 ... 24 => println!("less than 25"),
<anon>:4         25 => println!("exactly 25"),
<anon>:5         26 ... 255 => println!("above 25")
<anon>:6     }
<anon>:2:5: 6:6 help: see the detailed explanation for E0004
error: aborting due to previous error

The compiler isn't actually checking whether all the values for u8 are covered, it's just checking whether or not there's a case for _.

I've created some code that takes a Range<T> (the 'all-encompassing' range, i.e. 0...255 for u8) and Vec<Range<T>> where T: Ord + Copy and determines which ranges (if any) are not covered by the ranges provided by the vector. However, this code needs proper inclusive range support in order to work; I can't add 1 to the maximum value of a type in order to make it include every possible value for that type. That is available here.

I'm interested in implementing this logic in the compiler but I've no idea where to start, plus the code has the aforementioned inclusive range requirement.

@steveklabnik
Copy link
Member

/cc @rust-lang/lang

@arielb1
Copy link
Contributor

arielb1 commented Sep 18, 2015

known issue (duplicate of #12483)

@arielb1 arielb1 closed this as completed Sep 18, 2015
@steveklabnik steveklabnik added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants