rust/tests/ui/enum-discriminant/repr128.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.2 KiB
Rust
Raw Normal View History

2020-04-05 15:20:38 -05:00
// run-pass
#![feature(repr128, core_intrinsics, discriminant_kind)]
//~^ WARN the feature `repr128` is incomplete
2020-04-05 15:20:38 -05:00
use std::intrinsics::discriminant_value;
use std::marker::DiscriminantKind;
#[repr(i128)]
enum Signed {
Zero = 0,
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
2020-06-02 02:59:11 -05:00
U64Limit = u64::MAX as i128 + 1,
2020-04-05 15:20:38 -05:00
SmallNegative = -1,
2020-06-02 02:59:11 -05:00
BigNegative = i128::MIN,
2020-04-05 15:20:38 -05:00
Next,
}
#[repr(u128)]
enum Unsigned {
Zero = 0,
Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
2020-06-02 02:59:11 -05:00
U64Limit = u64::MAX as u128 + 1,
2020-04-05 15:20:38 -05:00
Next,
}
fn discr<T, U>(v: T, value: U)
where
<T as DiscriminantKind>::Discriminant: PartialEq<U>,
{
assert!(discriminant_value(&v) == value);
}
fn main() {
discr(Signed::Zero, 0);
discr(Signed::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
2020-06-02 02:59:11 -05:00
discr(Signed::U64Limit, u64::MAX as i128 + 1);
2020-04-05 15:20:38 -05:00
discr(Signed::SmallNegative, -1);
2020-06-02 02:59:11 -05:00
discr(Signed::BigNegative, i128::MIN);
discr(Signed::Next, i128::MIN + 1);
2020-04-05 15:20:38 -05:00
discr(Unsigned::Zero, 0);
discr(Unsigned::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
2020-06-02 02:59:11 -05:00
discr(Unsigned::U64Limit, u64::MAX as u128 + 1);
discr(Unsigned::Next, u64::MAX as u128 + 2);
2020-04-05 15:20:38 -05:00
}