Skip to content

Match arm treats ranges and conditions differently #74277

@kpp

Description

@kpp

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b57dd6cc254167f09d1a51f753ddebb6

fn main() {
    match 42u32 {
        x if x >= 0 => dbg!(x)
    };
}

Gives error:

error[E0004]: non-exhaustive patterns: `_` not covered
 --> src/main.rs:2:11
  |
2 |     match 42u32 {
  |           ^^^^^ pattern `_` not covered
  |
  = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
  = note: the matched value is of type `u32`

However this one with ranges compiles fine:

fn main() {
    match 42u32 {
        x @ 0..=std::u32::MAX => dbg!(x)
    };
}

I would expect x @ 0..=std::u32::MAX and x if x >= 0 be equal in match arms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions