Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pnkfelix opened this issue Jan 27, 2015 · 2 comments
Closed
Labels
A-codegen Area: Code generation

Comments

@pnkfelix
Copy link
Member

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)
@steveklabnik steveklabnik added the A-type-system Area: Type system label Jan 27, 2015
@pnkfelix pnkfelix added A-codegen Area: Code generation and removed A-type-system Area: Type system labels Jan 27, 2015
@pnkfelix
Copy link
Member Author

(to be clear: the bug here is not that the code above should be rejected. The code above is legal Rust, and should be accepted and run without error.)

@pnkfelix
Copy link
Member Author

cc @nick29581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

2 participants