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.
This commit is contained in:
Samuel Holland 2018-09-16 18:27:56 +00:00
parent de9666f123
commit 283f2be142
3 changed files with 10 additions and 10 deletions

View File

@ -21,12 +21,12 @@ enum Bar {
union Union {
foo: &'static Foo,
bar: &'static Bar,
usize: &'static usize,
u8: &'static u8,
}
static BAR: usize = 42;
static BAR: u8 = 42;
static FOO: (&Foo, &Bar) = unsafe {(
Union { usize: &BAR }.foo,
Union { usize: &BAR }.bar,
Union { u8: &BAR }.foo,
Union { u8: &BAR }.bar,
)};
fn main() {}

View File

@ -19,12 +19,12 @@ enum Bar {
union Union {
foo: &'static Foo,
bar: &'static Bar,
usize: &'static usize,
u8: &'static u8,
}
static BAR: usize = 5;
static BAR: u8 = 5;
static FOO: (&Foo, &Bar) = unsafe {( //~ undefined behavior
Union { usize: &BAR }.foo,
Union { usize: &BAR }.bar,
Union { u8: &BAR }.foo,
Union { u8: &BAR }.bar,
)};
fn main() {}

View File

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