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