]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
0bf4aa26 | 2 | #![allow(unused_must_use)] |
b7449926 | 3 | // Test that we are able to reinitialize box with moved referent |
83c7162d XL |
4 | static mut ORDER: [usize; 3] = [0, 0, 0]; |
5 | static mut INDEX: usize = 0; | |
6 | ||
7 | struct Dropee (usize); | |
8 | ||
9 | impl Drop for Dropee { | |
10 | fn drop(&mut self) { | |
11 | unsafe { | |
12 | ORDER[INDEX] = self.0; | |
13 | INDEX = INDEX + 1; | |
14 | } | |
15 | } | |
16 | } | |
17 | ||
18 | fn add_sentintel() { | |
19 | unsafe { | |
20 | ORDER[INDEX] = 2; | |
21 | INDEX = INDEX + 1; | |
22 | } | |
23 | } | |
24 | ||
25 | fn main() { | |
26 | let mut x = Box::new(Dropee(1)); | |
27 | *x; // move out from `*x` | |
28 | add_sentintel(); | |
29 | *x = Dropee(3); // re-initialize `*x` | |
30 | {x}; // drop value | |
31 | unsafe { | |
32 | assert_eq!(ORDER, [1, 2, 3]); | |
33 | } | |
34 | } |