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