1 // run-pass 2 #![allow(dead_code)] 3 #![feature(box_syntax)] 4 5 struct DroppableStruct; 6 enum DroppableEnum { 7 DroppableVariant1, DroppableVariant2 8 } 9 10 static mut DROPPED: bool = false; 11 12 impl Drop for DroppableStruct { drop(&mut self)13 fn drop(&mut self) { 14 unsafe { DROPPED = true; } 15 } 16 } 17 impl Drop for DroppableEnum { drop(&mut self)18 fn drop(&mut self) { 19 unsafe { DROPPED = true; } 20 } 21 } 22 dummy(&self)23trait MyTrait { fn dummy(&self) { } } 24 impl MyTrait for Box<DroppableStruct> {} 25 impl MyTrait for Box<DroppableEnum> {} 26 27 struct Whatever { w: Box<dyn MyTrait+'static> } 28 impl Whatever { new(w: Box<dyn MyTrait+'static>) -> Whatever29 fn new(w: Box<dyn MyTrait+'static>) -> Whatever { 30 Whatever { w: w } 31 } 32 } 33 main()34fn main() { 35 { 36 let f: Box<_> = box DroppableStruct; 37 let _a = Whatever::new(box f as Box<dyn MyTrait>); 38 } 39 assert!(unsafe { DROPPED }); 40 unsafe { DROPPED = false; } 41 { 42 let f: Box<_> = box DroppableEnum::DroppableVariant1; 43 let _a = Whatever::new(box f as Box<dyn MyTrait>); 44 } 45 assert!(unsafe { DROPPED }); 46 } 47