Skip to content

Commit 17a73cd

Browse files
committed
test for niche enum discriminant computation that overflows
1 parent 4f1c9bb commit 17a73cd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/run-pass/enums.rs

+24
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ fn test(me: MyEnum) {
2323
}
2424
}
2525

26+
fn discriminant_overflow() {
27+
// Tests for https://github.com/rust-lang/rust/issues/62138.
28+
#[repr(u8)]
29+
#[allow(dead_code)]
30+
enum WithWraparoundInvalidValues {
31+
X = 1,
32+
Y = 254,
33+
}
34+
35+
#[allow(dead_code)]
36+
enum Foo {
37+
A,
38+
B,
39+
C(WithWraparoundInvalidValues),
40+
}
41+
42+
let x = Foo::B;
43+
if let Foo::C(_) = x {
44+
panic!();
45+
}
46+
}
47+
2648
fn main() {
2749
test(MyEnum::MyEmptyVariant);
2850
test(MyEnum::MyNewtypeVariant(42));
@@ -31,4 +53,6 @@ fn main() {
3153
my_first_field: 45,
3254
my_second_field: 46,
3355
});
56+
57+
discriminant_overflow();
3458
}

0 commit comments

Comments
 (0)