Skip to content

Compiler doesn't realize that all match cases are covered #129354

@amab8901

Description

@amab8901

I tried this code:

fn main() {
    let a = 10.0_f64;
    let b = 20.0_f64;
    match a {
        a if a > b => {}
        a if a < b => {}
        a if a == b => {}
    };
}

I expected the compiler to realize that all cases have been covered, but instead the compiler says that "pattern _ not covered"

Meta

rustc --version --verbose:

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7
Backtrace

   Compiling nice v0.1.0 (/home/amir/src/nice)
error[E0004]: non-exhaustive patterns: `_` not covered
 --> src/main.rs:4:11
  |
4 |     match a {
  |           ^ pattern `_` not covered
  |
  = note: the matched value is of type `f64`
  = note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
7 ~         a if a == b => {},
8 +         _ => todo!()
  |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `nice` (bin "nice") due to 1 previous error

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