Skip to content

Can omit fields in pattern match #32004

Closed
@Aatch

Description

@Aatch

This code compiles on nightly:

enum Foo {
    Bar(i32),
    Baz
}

fn main() {
    let x = Foo::Bar(1);

    if let Foo::Bar = x {
        println!("Hello");
    }
}

Which it shouldn't, since Foo::Bar variant has a field and the pattern doesn't mention it. This can also cause an ICE:

enum Foo {
    Bar(i32),
    Baz
}

fn main() {
    match Foo::Bar(42) {
        Foo::Bar(x) => {},
        Foo::Bar => {},
        _ => {}
    }
}

Metadata

Metadata

Assignees

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions