match on bool: exhaustiveness not checked

Open
#4,967 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, rust
Domain
compilers

Research direction

Start with the Rust frontend’s match exhaustiveness checking and its existing tests; use the issue’s a.rs example as the reproduction. Run the relevant test suite and confirm that a bool match with only a true arm is rejected as non-exhaustive, while an exhaustive match still passes.

Written by the indexing model from the issue text.

Description

fn a(y: bool) {
    match y {
        true => (),
    }
}

this compiles @ 2e8c317e34dc5531ca3e7927e2abfdbce497c646 although we have no false arm 😅

rustc:

error[E0004]: non-exhaustive patterns: `false` not covered
 --> a.rs:2:11
  |
2 |     match y {
  |           ^ pattern `false` not covered
  |
  = note: the matched value is of type `bool`
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 ~         true => (),
4 ~         false => todo!(),
  |

error: aborting due to 2 previous errors
Dominant language
C++
Stars
3k
Forks
238
Avg merge
4d 8h
Merged PRs (30d)
31

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rust-GCC/gccrs

All issues in Rust-GCC/gccrs

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.