1 // Copyright 2014 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.
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.
11 #![allow(stable_features)]
12 #![feature(core, core_intrinsics)]
15 use core::intrinsics::discriminant_value;
44 enum NullablePointer {
45 Something(&'static u32),
49 static CONST : u32 = 0xBEEF;
54 assert_eq!(discriminant_value(&CLike1::A), 0);
55 assert_eq!(discriminant_value(&CLike1::B), 1);
56 assert_eq!(discriminant_value(&CLike1::C), 2);
57 assert_eq!(discriminant_value(&CLike1::D), 3);
59 assert_eq!(discriminant_value(&CLike2::A), 5);
60 assert_eq!(discriminant_value(&CLike2::B), 2);
61 assert_eq!(discriminant_value(&CLike2::C), 19);
62 assert_eq!(discriminant_value(&CLike2::D), 20);
64 assert_eq!(discriminant_value(&CLike3::A), 5);
65 assert_eq!(discriminant_value(&CLike3::B), 6);
66 assert_eq!(discriminant_value(&CLike3::C), -1_i8 as u64);
67 assert_eq!(discriminant_value(&CLike3::D), 0);
69 assert_eq!(discriminant_value(&ADT::First(0,0)), 0);
70 assert_eq!(discriminant_value(&ADT::Second(5)), 1);
72 assert_eq!(discriminant_value(&NullablePointer::Nothing), 1);
73 assert_eq!(discriminant_value(&NullablePointer::Something(&CONST)), 0);
75 assert_eq!(discriminant_value(&10), 0);
76 assert_eq!(discriminant_value(&"test"), 0);