]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-10802.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / issue-10802.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 #![allow(unknown_features)]
13 #![feature(box_syntax)]
14
15 struct DroppableStruct;
16 enum DroppableEnum {
17     DroppableVariant1, DroppableVariant2
18 }
19
20 static mut DROPPED: bool = false;
21
22 impl Drop for DroppableStruct {
23     fn drop(&mut self) {
24         unsafe { DROPPED = true; }
25     }
26 }
27 impl Drop for DroppableEnum {
28     fn drop(&mut self) {
29         unsafe { DROPPED = true; }
30     }
31 }
32
33 trait MyTrait { fn dummy(&self) { } }
34 impl MyTrait for Box<DroppableStruct> {}
35 impl MyTrait for Box<DroppableEnum> {}
36
37 struct Whatever { w: Box<MyTrait+'static> }
38 impl  Whatever {
39     fn new(w: Box<MyTrait+'static>) -> Whatever {
40         Whatever { w: w }
41     }
42 }
43
44 fn main() {
45     {
46         let f: Box<_> = box DroppableStruct;
47         let _a = Whatever::new(box f as Box<MyTrait>);
48     }
49     assert!(unsafe { DROPPED });
50     unsafe { DROPPED = false; }
51     {
52         let f: Box<_> = box DroppableEnum::DroppableVariant1;
53         let _a = Whatever::new(box f as Box<MyTrait>);
54     }
55     assert!(unsafe { DROPPED });
56 }