2019-05-09 16:08:55 -05:00
|
|
|
// run-pass
|
2018-09-14 05:20:28 -05:00
|
|
|
#![allow(stable_features)]
|
2022-04-05 20:21:10 -05:00
|
|
|
#![feature(core, core_intrinsics)]
|
2015-04-10 09:14:00 -05:00
|
|
|
|
2015-01-10 18:51:58 -06:00
|
|
|
extern crate core;
|
|
|
|
use core::intrinsics::discriminant_value;
|
|
|
|
|
|
|
|
enum CLike1 {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CLike2 {
|
|
|
|
A = 5,
|
|
|
|
B = 2,
|
|
|
|
C = 19,
|
|
|
|
D
|
|
|
|
}
|
|
|
|
|
2015-04-10 09:14:00 -05:00
|
|
|
#[repr(i8)]
|
|
|
|
enum CLike3 {
|
|
|
|
A = 5,
|
|
|
|
B,
|
|
|
|
C = -1,
|
|
|
|
D
|
|
|
|
}
|
|
|
|
|
2022-07-25 15:36:03 -05:00
|
|
|
#[allow(unused_tuple_struct_fields)]
|
2015-01-10 18:51:58 -06:00
|
|
|
enum ADT {
|
|
|
|
First(u32, u32),
|
|
|
|
Second(u64)
|
|
|
|
}
|
|
|
|
|
|
|
|
enum NullablePointer {
|
2022-07-25 15:36:03 -05:00
|
|
|
Something(#[allow(unused_tuple_struct_fields)] &'static u32),
|
2015-01-10 18:51:58 -06:00
|
|
|
Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
static CONST : u32 = 0xBEEF;
|
|
|
|
|
2019-05-09 16:08:55 -05:00
|
|
|
#[allow(dead_code)]
|
|
|
|
#[repr(isize)]
|
|
|
|
enum Mixed {
|
|
|
|
Unit = 3,
|
|
|
|
Tuple(u16) = 2,
|
|
|
|
Struct {
|
|
|
|
a: u8,
|
|
|
|
b: u16,
|
|
|
|
} = 1,
|
|
|
|
}
|
|
|
|
|
2015-01-10 18:51:58 -06:00
|
|
|
pub fn main() {
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike1::A), 0isize);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike1::B), 1);
|
|
|
|
assert_eq!(discriminant_value(&CLike1::C), 2);
|
|
|
|
assert_eq!(discriminant_value(&CLike1::D), 3);
|
2015-01-10 18:51:58 -06:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike2::A), 5isize);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike2::B), 2);
|
|
|
|
assert_eq!(discriminant_value(&CLike2::C), 19);
|
|
|
|
assert_eq!(discriminant_value(&CLike2::D), 20);
|
2015-01-10 18:51:58 -06:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike3::A), 5i8);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike3::B), 6);
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike3::C), -1);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&CLike3::D), 0);
|
2015-01-10 18:51:58 -06:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&ADT::First(0,0)), 0isize);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&ADT::Second(5)), 1);
|
2015-04-10 09:14:00 -05:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&NullablePointer::Nothing), 1isize);
|
2019-10-25 05:03:34 -05:00
|
|
|
assert_eq!(discriminant_value(&NullablePointer::Something(&CONST)), 0);
|
2015-01-10 18:51:58 -06:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&10), 0u8);
|
|
|
|
assert_eq!(discriminant_value(&"test"), 0u8);
|
2015-01-10 18:51:58 -06:00
|
|
|
|
2020-04-05 13:37:10 -05:00
|
|
|
assert_eq!(discriminant_value(&Mixed::Unit), 3isize);
|
|
|
|
assert_eq!(discriminant_value(&Mixed::Tuple(5)), 2);
|
|
|
|
assert_eq!(discriminant_value(&Mixed::Struct{a: 7, b: 11}), 1);
|
2015-01-10 18:51:58 -06:00
|
|
|
}
|