Skip to content

Segfault when matching on enums #38002

Closed
Closed
@justinj

Description

@justinj

This code (playground link) gives me a segfault on the current beta:

#[derive(Clone, Copy)]
enum Bar {
    C
}

#[derive(Clone, Copy)]
enum Foo {
    A {},
    B {
        y: f64,
        z: Bar
    },
}

fn f(s: &Foo) {
    match s {
        &Foo::A {} => {
        },
        &Foo::B { y: _y, z: ref _side } => {
        }
    }
}

const LIST: [(usize, Foo); 2] = [
    (51, Foo::B {
        y: 0.,
        z: Bar::C
    }),
    (52, Foo::B {
        y: 0.,
        z: Bar::C
    }),
];

pub fn main() {
    for &r in LIST.iter() {
        let (i, s) = r;
        println!("{}", i);
        f(&s);
    }
}

I've reduced it as much as I can, even removing the A constructor on the enum causes it to work.

I expect the output to be

51
52

(which it is on stable),
but instead I get

51
0
<segfault>

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions