rust/src/test/ui/consts/const_discriminant.rs

36 lines
857 B
Rust
Raw Normal View History

2020-03-08 13:24:32 +00:00
// run-pass
#![feature(const_discriminant)]
use std::mem::{discriminant, Discriminant};
fn identity<T>(x: T) -> T { x }
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);
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);
assert_eq!(TEST_A, discriminant(identity(&Test::A(17))));
assert_eq!(TEST_B, discriminant(identity(&Test::B)));
2020-03-08 13:24:32 +00:00
assert_ne!(TEST_A, TEST_B);
assert_ne!(TEST_B, discriminant(identity(&Test::C { a: 42, b: 7 })));
assert_eq!(TEST_V, discriminant(identity(&SingleVariant::V)));
2020-03-08 13:24:32 +00:00
}