]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | // run-pass |
1a4d82fc JJ |
2 | // This test verifies that temporaries created for `while`'s and `if` |
3 | // conditions are dropped after the condition is evaluated. | |
4 | ||
1a4d82fc JJ |
5 | #![feature(box_syntax)] |
6 | ||
7 | struct Temporary; | |
8 | ||
c34b1796 | 9 | static mut DROPPED: isize = 0; |
1a4d82fc JJ |
10 | |
11 | impl Drop for Temporary { | |
12 | fn drop(&mut self) { | |
13 | unsafe { DROPPED += 1; } | |
14 | } | |
15 | } | |
16 | ||
17 | impl Temporary { | |
18 | fn do_stuff(&self) -> bool {true} | |
19 | } | |
20 | ||
21 | fn borrow() -> Box<Temporary> { box Temporary } | |
22 | ||
23 | ||
24 | pub fn main() { | |
25 | let mut i = 0; | |
26 | ||
27 | // This loop's condition | |
28 | // should call `Temporary`'s | |
29 | // `drop` 6 times. | |
30 | while borrow().do_stuff() { | |
31 | i += 1; | |
32 | unsafe { assert_eq!(DROPPED, i) } | |
33 | if i > 5 { | |
34 | break; | |
35 | } | |
36 | } | |
37 | ||
38 | // This if condition should | |
39 | // call it 1 time | |
40 | if borrow().do_stuff() { | |
41 | unsafe { assert_eq!(DROPPED, i + 1) } | |
42 | } | |
43 | } |