Skip to content

Trait object implicit coercions through a match are incorrectly codegen'd #20419

@huonw

Description

@huonw
trait Foo {}
impl Foo for () {}

#[cfg(not(good))]
fn foo(x: bool) -> Box<Foo+'static> {
    match x {
        true => box() (),
        false => box() ()
    }
}
#[cfg(good)]
fn foo(x: bool) -> Box<Foo+'static> {
    match x {
        true => box() () as Box<Foo>,
        false => box() () as Box<Foo>
    }
}

fn main() {
    foo(true);
    foo(false);
}

Compiling with --cfg good (i.e. explicit casts) runs 100% fine, compiling without it (i.e. implicit coercions) segfaults/crashes. This also runs fine on 0.12 on the playpen, and with if x { instead of match .

cc @nick29581 (maybe?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions