]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-valgrind/cast-enum-with-dtor.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / run-pass-valgrind / cast-enum-with-dtor.rs
CommitLineData
923072b8 1#![allow(dead_code, cenum_impl_drop_cast)]
62682a34
SL
2
3// check dtor calling order when casting enums.
4
5use std::sync::atomic;
6use std::sync::atomic::Ordering;
7use std::mem;
8
9enum E {
10 A = 0,
11 B = 1,
12 C = 2
13}
14
15static FLAG: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
16
17impl 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
26fn main() {
27 assert_eq!(FLAG.load(Ordering::SeqCst), 0);
28 {
29 let e = E::C;
30 assert_eq!(e as u32, 2);
f2b60f7d 31 assert_eq!(FLAG.load(Ordering::SeqCst), 1);
62682a34 32 }
064997fb 33 assert_eq!(FLAG.load(Ordering::SeqCst), 1);
62682a34 34}