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

Bogus "non-exhaustive patterns" error with half-open range patterns on isize/usize #111859

Closed
Jules-Bertholet opened this issue May 23, 2023 · 3 comments
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug.

Comments

@Jules-Bertholet
Copy link
Contributor

Jules-Bertholet commented May 23, 2023

I tried this code:

fn test(a: usize) {
    match a {
        0.. => (),
    }
}

I expected to see this happen: Successful compilation, the match is exhaustive

Instead, this happened:

error[E0004]: non-exhaustive patterns: `_` not covered
 --> src/lib.rs:2:11
  |
2 |     match a {
  |           ^ pattern `_` not covered
  |
  = note: the matched value is of type `usize`
  = note: `usize` does not have a fixed maximum value, so a wildcard `_` is necessary to match exhaustively
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
3 ~         0.. => (),
4 ~         _ => todo!(),
  |

For more information about this error, try `rustc --explain E0004`.

isize (with ..=0 and 1.. patterns) has the same issue, but the other numeric types don't.

Meta

rustc --version --verbose:

1.71.0-nightly (2023-05-21 9d871b0617a4b3d6610b)

@rustbot label A-patterns A-exhaustiveness-checking

@Jules-Bertholet Jules-Bertholet added the C-bug Category: This is a bug. label May 23, 2023
@rustbot rustbot added the A-patterns Relating to patterns and pattern matching label May 23, 2023
@Jules-Bertholet Jules-Bertholet changed the title Bogus non-exhaustive patterns with half-open range patterns and isize/usize Bogus "non-exhaustive patterns" error with half-open range patterns and isize/usize May 23, 2023
@Jules-Bertholet Jules-Bertholet changed the title Bogus "non-exhaustive patterns" error with half-open range patterns and isize/usize Bogus "non-exhaustive patterns" error with half-open range patterns on isize/usize May 23, 2023
@lukas-code
Copy link
Member

see also #56354

@rustbot rustbot added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Jun 26, 2023
@rlidwka
Copy link

rlidwka commented Sep 21, 2023

I've just ran into this issue with a code similar to this:

fn test(vec: Vec<f64>) -> &'static str {
    match vec.len() {
        2.. => "two or more items",
        1 => "one item",
        0 => "zero items",
    }
}

easy to work around, but the error is very much unexpected

@Nadrieril
Copy link
Member

This is now fixed (#116692)! You example is accepted on nightly (playground) and soon will in stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants