]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-10802.rs
ab080834ac94b85c70a8d164024b13074d4553e4
[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 struct DroppableStruct;
12 enum DroppableEnum {
13     DroppableVariant1, DroppableVariant2
14 }
15
16 static mut DROPPED: bool = false;
17
18 impl Drop for DroppableStruct {
19     fn drop(&mut self) {
20         unsafe { DROPPED = true; }
21     }
22 }
23 impl Drop for DroppableEnum {
24     fn drop(&mut self) {
25         unsafe { DROPPED = true; }
26     }
27 }
28
29 trait MyTrait { }
30 impl MyTrait for Box<DroppableStruct> {}
31 impl MyTrait for Box<DroppableEnum> {}
32
33 struct Whatever { w: Box<MyTrait+'static> }
34 impl  Whatever {
35     fn new(w: Box<MyTrait+'static>) -> Whatever {
36         Whatever { w: w }
37     }
38 }
39
40 fn main() {
41     {
42         let f = box DroppableStruct;
43         let _a = Whatever::new(box f as Box<MyTrait>);
44     }
45     assert!(unsafe { DROPPED });
46     unsafe { DROPPED = false; }
47     {
48         let f = box DroppableEnum::DroppableVariant1;
49         let _a = Whatever::new(box f as Box<MyTrait>);
50     }
51     assert!(unsafe { DROPPED });
52 }