]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/struct-order-of-eval-4.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / struct-order-of-eval-4.rs
CommitLineData
c34b1796
AL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// Checks that struct-literal expression order-of-eval is as expected
12// even when no Drop-implementations are involved.
13
62682a34 14#![feature(const_fn)]
c34b1796 15
62682a34 16use std::sync::atomic::{Ordering, AtomicUsize};
c34b1796
AL
17
18struct W { wrapped: u32 }
19struct S { f0: W, _f1: i32 }
20
21pub fn main() {
22 const VAL: u32 = 0x89AB_CDEF;
23 let w = W { wrapped: VAL };
24 let s = S {
25 _f1: { event(0x01); 23 },
26 f0: { event(0x02); w },
27 };
28 assert_eq!(s.f0.wrapped, VAL);
29 let actual = event_log();
30 let expect = 0x01_02;
31 assert!(expect == actual,
32 "expect: 0x{:x} actual: 0x{:x}", expect, actual);
33}
34
62682a34 35static LOG: AtomicUsize = AtomicUsize::new(0);
c34b1796
AL
36
37fn event_log() -> usize {
38 LOG.load(Ordering::SeqCst)
39}
40
41fn event(tag: u8) {
42 let old_log = LOG.load(Ordering::SeqCst);
43 let new_log = (old_log << 8) + tag as usize;
44 LOG.store(new_log, Ordering::SeqCst);
45}