Skip to content

drop in Box<Box<T>> as Box<Trait> broken #129

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

Closed
oli-obk opened this issue Feb 9, 2017 · 1 comment · Fixed by #136
Closed

drop in Box<Box<T>> as Box<Trait> broken #129

oli-obk opened this issue Feb 9, 2017 · 1 comment · Fixed by #136
Labels
C-bug Category: This is a bug.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2017

rust-lang/rust#39230 changed some things around with boxed, especially that there is a "Drop impl" now: https://github.com/rust-lang/rust/blame/master/src/liballoc/boxed.rs#L297 (it's empty, doesn't drop its contents)

We should just wait for rustc to fix it.

repro:

#![feature(box_syntax)]

struct DroppableStruct;

static mut DROPPED: bool = false;

impl Drop for DroppableStruct {
    fn drop(&mut self) {
        unsafe { DROPPED = true; }
    }
}

trait MyTrait { fn dummy(&self) { } }
impl MyTrait for Box<DroppableStruct> {}

struct Whatever { w: Box<MyTrait+'static> }
impl  Whatever {
    fn new(w: Box<MyTrait+'static>) -> Whatever {
        Whatever { w: w }
    }
}

fn main() {
    {
        let f: Box<_> = box DroppableStruct;
        let _a = Whatever::new(box f as Box<MyTrait>);
    }
    assert!(unsafe { DROPPED });
}
@solson solson added the C-bug Category: This is a bug. label Feb 9, 2017
@eddyb
Copy link
Member

eddyb commented Feb 9, 2017

We don't plan to fix this in rustc, you have to check if it's a Box specifically.

erickt pushed a commit to erickt/miri that referenced this issue Feb 4, 2022
Build serde without default features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants