Skip to content

Commit

Permalink
Fix double_check tests on big-endian targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smaeul committed Nov 1, 2018
1 parent de9666f commit 283f2be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/test/ui/consts/const-eval/double_check.rs
Expand Up @@ -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() {}
8 changes: 4 additions & 4 deletions src/test/ui/consts/const-eval/double_check2.rs
Expand Up @@ -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() {}
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-eval/double_check2.stderr
Expand Up @@ -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>
|
Expand Down

0 comments on commit 283f2be

Please sign in to comment.