Skip to content

Invalid branching in wildcard pattern #2144

@CohenArthur

Description

@CohenArthur

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: 428a318

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions