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

Matching on modulo failure. #46759

Closed
44100hertz opened this issue Dec 16, 2017 · 2 comments
Closed

Matching on modulo failure. #46759

44100hertz opened this issue Dec 16, 2017 · 2 comments

Comments

@44100hertz
Copy link

44100hertz commented Dec 16, 2017

When matching on an unsigned modulus, I can cover all possible branches and still get a complaint.

fn thing(i: u8) -> &'static str {
    match i % 3 {
        0 => "Zero",
        1 => "One",
        2 => "Two",
    }
}
error[E0004]: non-exhaustive patterns: `_` not covered
 --> /tmp/modmatch.rs:2:11
  |
2 |     match i % 3 {
  |           ^^^^^ pattern `_` not covered

This is easily covered with _ => unreachable!(), possibly the most idiomatic use of said macro. I just wonder if it's possible for rust to be a bit smarter about this type of case.

@est31
Copy link
Member

est31 commented Dec 16, 2017

related issue: rust-lang/rfcs#1550

@arielb1
Copy link
Contributor

arielb1 commented Dec 17, 2017

This should be an RFC - this is a more general version of rust-lang/rfcs#1550. IIRC we already rejected it several times so you might want to look at the history of this proposal before writing one.

Closing this issue because of that.

@arielb1 arielb1 closed this as completed Dec 17, 2017
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

3 participants