Rust-GCC / Rust-GCC/gccrs

Invalid branching in wildcard pattern

Open
#2,144 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:

enum Foo {
    A,
    B(i32),
}

fn main() -> i32 {
    let result = Foo::B(123);

    // { dg-warning "statement will never be executed" "" { target *-*-* } .+1 }
    let value = match result {
        A => 15,
        Foo::B(x) => x,
    };

    value - 15
}

I expected to see this happen: running this program exits with a 0 exit code.

The "equivalent" Rust code being:

enum Foo {
    A,
    B(i32),
}

fn main() {
    let result = Foo::B(123);

    // { dg-error "statement will never be executed" "" { target *-*-* } .+1 }
    let value = match result {
        A => 15,
        Foo::B(x) => x,
    };

    println!("{}", value - 15)
}

which gives out a lot of warnings but prints zero.

Instead, this happened: the code exited with 108 as a return value, which is 123 - 15

Meta
  • What version of Rust GCC were you using: 428a31804b8

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

Run the supplied Rust reproducer with the recorded gccrs revision and compare its exit status with the expected 0. Trace how the compiler handles the match arms and the unqualified variant pattern; done means the reproducer exits 0 while retaining the relevant diagnostics shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.