]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-10734.rs
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
[rust.git] / src / test / ui / issues / issue-10734.rs
1 // run-pass
2 #![allow(non_upper_case_globals)]
3
4 static mut drop_count: usize = 0;
5
6 struct Foo {
7     dropped: bool
8 }
9
10 impl Drop for Foo {
11     fn drop(&mut self) {
12         // Test to make sure we haven't dropped already
13         assert!(!self.dropped);
14         self.dropped = true;
15         // And record the fact that we dropped for verification later
16         unsafe { drop_count += 1; }
17     }
18 }
19
20 pub fn main() {
21     // An `if true { expr }` statement should compile the same as `{ expr }`.
22     if true {
23         let _a = Foo{ dropped: false };
24     }
25     // Check that we dropped already (as expected from a `{ expr }`).
26     unsafe { assert_eq!(drop_count, 1); }
27
28     // An `if false {} else { expr }` statement should compile the same as `{ expr }`.
29     if false {
30         panic!();
31     } else {
32         let _a = Foo{ dropped: false };
33     }
34     // Check that we dropped already (as expected from a `{ expr }`).
35     unsafe { assert_eq!(drop_count, 2); }
36 }