]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/structs-enums/enum-discrim-width-stuff.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / structs-enums / enum-discrim-width-stuff.rs
1 // Copyright 2013 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 // run-pass
12 #![allow(overflowing_literals)]
13 #![allow(dead_code)]
14
15 macro_rules! check {
16 ($m:ident, $t:ty, $v:expr) => {{
17 mod $m {
18 use std::mem::size_of;
19 #[derive(Copy, Clone, Debug)]
20 enum E {
21 V = $v,
22 A = 0
23 }
24 static C: E = E::V;
25 pub fn check() {
26 assert_eq!(size_of::<E>(), size_of::<$t>());
27 assert_eq!(E::V as $t, $v as $t);
28 assert_eq!(C as $t, $v as $t);
29 assert_eq!(format!("{:?}", E::V), "V".to_string());
30 assert_eq!(format!("{:?}", C), "V".to_string());
31 }
32 }
33 $m::check();
34 }}
35 }
36
37 pub fn main() {
38 check!(a, u8, 0x17);
39 check!(b, u8, 0xe8);
40 check!(c, u16, 0x1727);
41 check!(d, u16, 0xe8d8);
42 check!(e, u32, 0x17273747);
43 check!(f, u32, 0xe8d8c8b8);
44
45 check!(z, i8, 0x17);
46 check!(y, i8, -0x17);
47 check!(x, i16, 0x1727);
48 check!(w, i16, -0x1727);
49 check!(v, i32, 0x17273747);
50 check!(u, i32, -0x17273747);
51
52 enum Simple { A, B }
53 assert_eq!(::std::mem::size_of::<Simple>(), 1);
54 }