Rust-GCC / Rust-GCC/gccrs

pattern check ignores if guards

Open
#3,173 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Summary

related to https://github.com/Rust-GCC/gccrs/issues/3172

Reproducer

I tried this code:

enum E {
    A(),
    B(),
}

fn f(e: E) {
    match e {
        E::A() if true => {}
        //E::B => {}
    }
}

Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/97fnfov7h

Actual behavior

The current behavior is...

<source>:7:11: error: non-exhaustive patterns: 'E::B()' not covered
    7 |     match e {
      |           ^
Compiler returned: 1
Expected behavior

I expected to see...

error[E0004]: non-exhaustive patterns: `A` and `B` not covered
 --> <source>:7:11
  |
1 | / enum E {
2 | |     A(),
  | |     - not covered
3 | |     B(),
  | |     - not covered
4 | | }
  | |_- `E` defined here
...
7 |       match e {
  |             ^ patterns `A` and `B` 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 `E`

error: aborting due to previous error
GCC Version

67bc0f69b46b2e4c335017aba3bc1218574aad7a

Contributor guide

Open the contributing guide

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.

Research direction

Start by compiling the Rust reproducer from the issue, or open the provided Godbolt link, and compare its behavior with the expected exhaustiveness diagnostic. Investigate the compiler's pattern-checking path for match arms with if guards; done means the guarded arm is handled correctly and the resulting diagnostic matches the expected non-exhaustive-pattern behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.