]> git.proxmox.com Git - rustc.git/blame - src/test/ui/drop/issue-48962.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / drop / issue-48962.rs
CommitLineData
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
4static mut ORDER: [usize; 3] = [0, 0, 0];
5static mut INDEX: usize = 0;
6
7struct Dropee (usize);
8
9impl Drop for Dropee {
10 fn drop(&mut self) {
11 unsafe {
12 ORDER[INDEX] = self.0;
13 INDEX = INDEX + 1;
14 }
15 }
16}
17
18fn add_sentintel() {
19 unsafe {
20 ORDER[INDEX] = 2;
21 INDEX = INDEX + 1;
22 }
23}
24
25fn 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}