]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-48962.rs
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
[rust.git] / src / test / ui / 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 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 }