Skip to content

Commit 6239b35

Browse files
committed
Add tests for Result<u32, (u32, !)> layout. The comments will be accurate after the commits which add the relevant layout optimizations.
1 parent 97c1a33 commit 6239b35

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/ui/consts/const-eval/ub-enum.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem:
100100
const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
101101
//~^ ERROR uninhabited enum variant
102102

103+
// All variants have same-size data but only one inhabited.
104+
// Use `0` as constant to make behavior endianness-independent.
105+
const GOOD_SEMIINHABITED_WITH_DATA1: Result<i32, (i32, !)> = unsafe { mem::transmute(0u64) };
106+
const GOOD_SEMIINHABITED_WITH_DATA2: Result<(i32, !), i32> = unsafe { mem::transmute(1u64) };
107+
103108
const TEST_ICE_89765: () = {
104109
// This is a regression test for https://github.com/rust-lang/rust/issues/89765.
105110
unsafe {

tests/ui/consts/const-eval/ub-enum.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe {
121121
| ^^^^^^^^^^^^^^^^^^^^ evaluation of `BAD_UNINHABITED_WITH_DATA2` failed here
122122

123123
error[E0080]: read discriminant of an uninhabited enum variant
124-
--> $DIR/ub-enum.rs:106:9
124+
--> $DIR/ub-enum.rs:111:9
125125
|
126126
LL | std::mem::discriminant(&*(&() as *const () as *const Never));
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `TEST_ICE_89765` failed inside this call

0 commit comments

Comments
 (0)