]>
Commit | Line | Data |
---|---|---|
923072b8 | 1 | #![allow(dead_code, cenum_impl_drop_cast)] |
62682a34 SL |
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); | |
f2b60f7d | 31 | assert_eq!(FLAG.load(Ordering::SeqCst), 1); |
62682a34 | 32 | } |
064997fb | 33 | assert_eq!(FLAG.load(Ordering::SeqCst), 1); |
62682a34 | 34 | } |