2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(dead_code)]
|
2015-01-07 19:25:56 -06:00
|
|
|
|
2014-04-27 22:27:20 -05:00
|
|
|
struct DroppableStruct;
|
2014-06-14 08:55:55 -05:00
|
|
|
enum DroppableEnum {
|
|
|
|
DroppableVariant1, DroppableVariant2
|
|
|
|
}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
|
|
|
static mut DROPPED: bool = false;
|
|
|
|
|
|
|
|
impl Drop for DroppableStruct {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { DROPPED = true; }
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 08:55:55 -05:00
|
|
|
impl Drop for DroppableEnum {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { DROPPED = true; }
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
2015-02-12 09:29:52 -06:00
|
|
|
trait MyTrait { fn dummy(&self) { } }
|
2014-05-05 20:56:44 -05:00
|
|
|
impl MyTrait for Box<DroppableStruct> {}
|
2014-06-14 08:55:55 -05:00
|
|
|
impl MyTrait for Box<DroppableEnum> {}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
struct Whatever { w: Box<dyn MyTrait+'static> }
|
2014-04-27 22:27:20 -05:00
|
|
|
impl Whatever {
|
2019-05-28 13:47:21 -05:00
|
|
|
fn new(w: Box<dyn MyTrait+'static>) -> Whatever {
|
2014-04-27 22:27:20 -05:00
|
|
|
Whatever { w: w }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
{
|
2022-07-06 21:36:10 -05:00
|
|
|
let f: Box<_> = Box::new(DroppableStruct);
|
|
|
|
let _a = Whatever::new(Box::new(f) as Box<dyn MyTrait>);
|
2014-04-27 22:27:20 -05:00
|
|
|
}
|
|
|
|
assert!(unsafe { DROPPED });
|
2014-06-14 08:55:55 -05:00
|
|
|
unsafe { DROPPED = false; }
|
|
|
|
{
|
2022-07-06 21:36:10 -05:00
|
|
|
let f: Box<_> = Box::new(DroppableEnum::DroppableVariant1);
|
|
|
|
let _a = Whatever::new(Box::new(f) as Box<dyn MyTrait>);
|
2014-06-14 08:55:55 -05:00
|
|
|
}
|
|
|
|
assert!(unsafe { DROPPED });
|
2014-04-27 22:27:20 -05:00
|
|
|
}
|