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