Skip to content

Commit 283f2be

Browse files
committed
Fix double_check tests on big-endian targets
Since the enums get optimized down to 1 byte long, the bits set in the usize member don't align with the enums on big-endian machines. Avoid this issue by shrinking the integer member to the same size as the enums.
1 parent de9666f commit 283f2be

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/test/ui/consts/const-eval/double_check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ enum Bar {
2121
union Union {
2222
foo: &'static Foo,
2323
bar: &'static Bar,
24-
usize: &'static usize,
24+
u8: &'static u8,
2525
}
26-
static BAR: usize = 42;
26+
static BAR: u8 = 42;
2727
static FOO: (&Foo, &Bar) = unsafe {(
28-
Union { usize: &BAR }.foo,
29-
Union { usize: &BAR }.bar,
28+
Union { u8: &BAR }.foo,
29+
Union { u8: &BAR }.bar,
3030
)};
3131

3232
fn main() {}

src/test/ui/consts/const-eval/double_check2.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ enum Bar {
1919
union Union {
2020
foo: &'static Foo,
2121
bar: &'static Bar,
22-
usize: &'static usize,
22+
u8: &'static u8,
2323
}
24-
static BAR: usize = 5;
24+
static BAR: u8 = 5;
2525
static FOO: (&Foo, &Bar) = unsafe {( //~ undefined behavior
26-
Union { usize: &BAR }.foo,
27-
Union { usize: &BAR }.bar,
26+
Union { u8: &BAR }.foo,
27+
Union { u8: &BAR }.bar,
2828
)};
2929

3030
fn main() {}

src/test/ui/consts/const-eval/double_check2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/double_check2.rs:25:1
33
|
44
LL | / static FOO: (&Foo, &Bar) = unsafe {( //~ undefined behavior
5-
LL | | Union { usize: &BAR }.foo,
6-
LL | | Union { usize: &BAR }.bar,
5+
LL | | Union { u8: &BAR }.foo,
6+
LL | | Union { u8: &BAR }.bar,
77
LL | | )};
88
| |___^ type validation failed: encountered invalid enum discriminant 5 at .1.<deref>
99
|

0 commit comments

Comments
 (0)