]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-valgrind/cast-enum-with-dtor.rs
Merge tag 'debian/1.65.0+dfsg1-1_exp3' into debian/sid
[rustc.git] / src / test / run-pass-valgrind / cast-enum-with-dtor.rs
1 #![allow(dead_code, cenum_impl_drop_cast)]
2
3 // check dtor calling order when casting enums.
4
5 use std::sync::atomic;
6 use std::sync::atomic::Ordering;
7 use std::mem;
8
9 enum E {
10 A = 0,
11 B = 1,
12 C = 2
13 }
14
15 static FLAG: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
16
17 impl Drop for E {
18 fn drop(&mut self) {
19 // avoid dtor loop
20 unsafe { mem::forget(mem::replace(self, E::B)) };
21
22 FLAG.store(FLAG.load(Ordering::SeqCst)+1, Ordering::SeqCst);
23 }
24 }
25
26 fn main() {
27 assert_eq!(FLAG.load(Ordering::SeqCst), 0);
28 {
29 let e = E::C;
30 assert_eq!(e as u32, 2);
31 assert_eq!(FLAG.load(Ordering::SeqCst), 1);
32 }
33 assert_eq!(FLAG.load(Ordering::SeqCst), 1);
34 }