]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-10802.rs
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
[rust.git] / src / test / ui / issues / issue-10802.rs
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 {
13     fn drop(&mut self) {
14         unsafe { DROPPED = true; }
15     }
16 }
17 impl Drop for DroppableEnum {
18     fn drop(&mut self) {
19         unsafe { DROPPED = true; }
20     }
21 }
22
23 trait 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 {
29     fn new(w: Box<dyn MyTrait+'static>) -> Whatever {
30         Whatever { w: w }
31     }
32 }
33
34 fn 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 }