2020-03-08 13:24:32 +00:00
|
|
|
// run-pass
|
2020-09-07 11:04:41 +00:00
|
|
|
#![feature(const_discriminant)]
|
2020-03-08 17:56:15 +00:00
|
|
|
#![allow(dead_code)]
|
2020-03-08 13:24:32 +00:00
|
|
|
|
|
|
|
use std::mem::{discriminant, Discriminant};
|
2020-09-07 09:37:35 +00:00
|
|
|
use std::hint::black_box;
|
2020-03-08 14:12:46 +00:00
|
|
|
|
2020-03-08 13:24:32 +00:00
|
|
|
enum Test {
|
|
|
|
A(u8),
|
|
|
|
B,
|
|
|
|
C { a: u8, b: u8 },
|
|
|
|
}
|
|
|
|
|
|
|
|
const TEST_A: Discriminant<Test> = discriminant(&Test::A(5));
|
|
|
|
const TEST_A_OTHER: Discriminant<Test> = discriminant(&Test::A(17));
|
|
|
|
const TEST_B: Discriminant<Test> = discriminant(&Test::B);
|
|
|
|
|
2020-03-08 16:04:02 +00:00
|
|
|
enum Void {}
|
|
|
|
|
|
|
|
enum SingleVariant {
|
|
|
|
V,
|
|
|
|
Never(Void),
|
|
|
|
}
|
|
|
|
|
|
|
|
const TEST_V: Discriminant<SingleVariant> = discriminant(&SingleVariant::V);
|
|
|
|
|
2020-03-08 13:24:32 +00:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(TEST_A, TEST_A_OTHER);
|
2020-09-07 09:37:35 +00:00
|
|
|
assert_eq!(TEST_A, discriminant(black_box(&Test::A(17))));
|
|
|
|
assert_eq!(TEST_B, discriminant(black_box(&Test::B)));
|
2020-03-08 13:24:32 +00:00
|
|
|
assert_ne!(TEST_A, TEST_B);
|
2020-09-07 09:37:35 +00:00
|
|
|
assert_ne!(TEST_B, discriminant(black_box(&Test::C { a: 42, b: 7 })));
|
2020-03-08 16:04:02 +00:00
|
|
|
|
2020-09-07 09:37:35 +00:00
|
|
|
assert_eq!(TEST_V, discriminant(black_box(&SingleVariant::V)));
|
2020-03-08 13:24:32 +00:00
|
|
|
}
|