]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/struct-order-of-eval-4.rs
Override rustc version in ui and mir-opt tests to get stable hashes
[rust.git] / src / test / ui / structs-enums / struct-order-of-eval-4.rs
1 // run-pass
2 // Checks that struct-literal expression order-of-eval is as expected
3 // even when no Drop-implementations are involved.
4
5 use std::sync::atomic::{Ordering, AtomicUsize};
6
7 struct W { wrapped: u32 }
8 struct S { f0: W, _f1: i32 }
9
10 pub fn main() {
11     const VAL: u32 = 0x89AB_CDEF;
12     let w = W { wrapped: VAL };
13     let s = S {
14         _f1: { event(0x01); 23 },
15         f0: { event(0x02); w },
16     };
17     assert_eq!(s.f0.wrapped, VAL);
18     let actual = event_log();
19     let expect = 0x01_02;
20     assert!(expect == actual,
21             "expect: 0x{:x} actual: 0x{:x}", expect, actual);
22 }
23
24 static LOG: AtomicUsize = AtomicUsize::new(0);
25
26 fn event_log() -> usize {
27     LOG.load(Ordering::SeqCst)
28 }
29
30 fn event(tag: u8) {
31     let old_log = LOG.load(Ordering::SeqCst);
32     let new_log = (old_log << 8) + tag as usize;
33     LOG.store(new_log, Ordering::SeqCst);
34 }