Skip to content

Segfault in an unconditional drop call after a match #30530

Closed
@sfackler

Description

@sfackler

This code will segfault running drop glue for Box<Box<Fn()>>, even though a value of that type is not actually created.

enum Handler {
    Default,
    Custom(*mut Box<Fn()>),
}

fn main() {
    take();
}

fn take() -> Box<Fn()> {
    unsafe {
        match Handler::Default {
            Handler::Default => Box::new(main),
            Handler::Custom(ptr) => *Box::from_raw(ptr),
        }
    }
}

Interestingly, it exits successfully if the second match body is wrapped in a block.

Metadata

Metadata

Assignees

Labels

I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions