]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/enum-discrim-width-stuff.rs
Override rustc version in ui and mir-opt tests to get stable hashes
[rust.git] / src / test / ui / structs-enums / enum-discrim-width-stuff.rs
1 // run-pass
2 #![allow(overflowing_literals)]
3 #![allow(dead_code)]
4
5 macro_rules! check {
6     ($m:ident, $t:ty, $v:expr) => {{
7         mod $m {
8             use std::mem::size_of;
9             #[derive(Copy, Clone, Debug)]
10             enum E {
11                 V = $v,
12                 A = 0
13             }
14             static C: E = E::V;
15             pub fn check() {
16                 assert_eq!(size_of::<E>(), size_of::<$t>());
17                 assert_eq!(E::V as $t, $v as $t);
18                 assert_eq!(C as $t, $v as $t);
19                 assert_eq!(format!("{:?}", E::V), "V".to_string());
20                 assert_eq!(format!("{:?}", C), "V".to_string());
21             }
22         }
23         $m::check();
24     }}
25 }
26
27 pub fn main() {
28     check!(a, u8, 0x17);
29     check!(b, u8, 0xe8);
30     check!(c, u16, 0x1727);
31     check!(d, u16, 0xe8d8);
32     check!(e, u32, 0x17273747);
33     check!(f, u32, 0xe8d8c8b8);
34
35     check!(z, i8, 0x17);
36     check!(y, i8, -0x17);
37     check!(x, i16, 0x1727);
38     check!(w, i16, -0x1727);
39     check!(v, i32, 0x17273747);
40     check!(u, i32, -0x17273747);
41
42     enum Simple { A, B }
43     assert_eq!(::std::mem::size_of::<Simple>(), 1);
44 }