Skip to content

Commit

Permalink
Rollup merge of #55561 - smaeul:test-fixes, r=alexcrichton
Browse files Browse the repository at this point in the history
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 `enum` values on big-endian machines. Avoid this issue by shrinking the integer member to the
same size as the enums.
  • Loading branch information
kennytm committed Nov 1, 2018
2 parents 9550bc0 + 283f2be commit 1a25f22
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 1a25f22

Please sign in to comment.