test for niche enum discriminant computation that overflows

This commit is contained in:
Ralf Jung 2019-08-10 15:10:11 +02:00
parent d83bcbd339
commit 7e65c44714

View File

@ -23,6 +23,28 @@ fn test(me: MyEnum) {
}
}
fn discriminant_overflow() {
// Tests for https://github.com/rust-lang/rust/issues/62138.
#[repr(u8)]
#[allow(dead_code)]
enum WithWraparoundInvalidValues {
X = 1,
Y = 254,
}
#[allow(dead_code)]
enum Foo {
A,
B,
C(WithWraparoundInvalidValues),
}
let x = Foo::B;
if let Foo::C(_) = x {
panic!();
}
}
fn main() {
test(MyEnum::MyEmptyVariant);
test(MyEnum::MyNewtypeVariant(42));
@ -31,4 +53,6 @@ fn main() {
my_first_field: 45,
my_second_field: 46,
});
discriminant_overflow();
}