Skip to content

Coercing into Box<Trait> in a match arm does not get cleaned up properly. #21695

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #20055 (and PR #21692 )

I thought I fixed this and wrote a test for it in PR #21692, but I was wrong -- the test for Box<Trait> was erroneous/incomplete at best.

Test case:

trait Boo { }

impl Boo for [i8; 1] { }
impl Boo for [i8; 2] { }
impl Boo for [i8; 3] { }
impl Boo for [i8; 4] { }

pub fn foo(box_1: fn () -> Box<[i8; 1]>,
           box_2: fn () -> Box<[i8; 2]>,
           box_3: fn () -> Box<[i8; 3]>,
           box_4: fn () -> Box<[i8; 4]>,
            ) {
    let _b: Box<Boo> = match 3 {
        1 => box_1(),
        2 => box_2(),
        3 => box_3(),
        _ => box_4(),
    };
}

pub fn main() {
    fn box_1() -> Box<[i8; 1]> { Box::new( [1i8; 1] ) }
    fn box_2() -> Box<[i8; 2]> { Box::new( [1i8; 2] ) }
    fn box_3() -> Box<[i8; 3]> { Box::new( [1i8; 3] ) }
    fn box_4() -> Box<[i8; 4]> { Box::new( [1i8; 4] ) }

    println!("Hello World 1");
    foo(box_1, box_2, box_3, box_4);
    println!("Hello World 2");

}

In the playpen, this currently prints:

Hello World 1
playpen: application terminated abnormally with signal 4 (Illegal instruction)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions