properly extract the inner type in a drop impl
This commit is contained in:
parent
06a02187ba
commit
d92085fd0e
@ -165,9 +165,11 @@ pub fn drop(
|
||||
// some values don't need to call a drop impl, so the value is null
|
||||
if drop_fn != Pointer::from_int(0) {
|
||||
let FunctionDefinition {def_id, substs, sig, ..} = self.memory.get_fn(drop_fn.alloc_id)?.expect_drop_glue()?;
|
||||
let real_ty = sig.inputs()[0];
|
||||
let real_ty = match sig.inputs()[0].sty {
|
||||
ty::TyRef(_, mt) => self.monomorphize(mt.ty, substs),
|
||||
_ => bug!("first argument of Drop::drop must be &mut T"),
|
||||
};
|
||||
self.drop(Lvalue::from_ptr(ptr), real_ty, drop)?;
|
||||
drop.push((def_id, Value::ByVal(PrimVal::Ptr(ptr)), substs));
|
||||
} else {
|
||||
// just a sanity check
|
||||
assert_eq!(drop_fn.offset, 0);
|
||||
|
29
tests/run-pass/box_box_trait.rs
Normal file
29
tests/run-pass/box_box_trait.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#![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 });
|
||||
}
|
Loading…
Reference in New Issue
Block a user