Respect endianness correctly in CheckEnums test suite

The endianness can change the test expectation for the enum check.
This change is fixing the failing tests on big endian by changing
the tests so that they behave the same as on little endian.
This commit is contained in:
Bastian Kersting 2025-07-02 20:33:28 +03:00
parent 6268d0aa34
commit b4e68e212e
6 changed files with 14 additions and 15 deletions

View file

@ -1,6 +1,6 @@
//@ run-fail
//@ compile-flags: -C debug-assertions
//@ error-pattern: trying to construct an enum from an invalid value 0x10000
//@ error-pattern: trying to construct an enum from an invalid value
#[allow(dead_code)]
#[repr(u32)]
@ -11,10 +11,9 @@ enum Foo {
#[allow(dead_code)]
struct Bar {
a: u16,
b: u16,
a: u32,
}
fn main() {
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 1 }) };
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 3 }) };
}

View file

@ -10,11 +10,10 @@ enum Foo {
#[allow(dead_code)]
struct Bar {
a: u16,
b: u16,
a: u32,
}
fn main() {
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 0 }) };
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1, b: 0 }) };
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0 }) };
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1 }) };
}

View file

@ -1,8 +1,9 @@
//@ run-fail
//@ compile-flags: -C debug-assertions
//@ error-pattern: trying to construct an enum from an invalid value 0x3
//@ error-pattern: trying to construct an enum from an invalid value
#[allow(dead_code)]
#[repr(u32)]
enum Foo {
A,
B,
@ -10,11 +11,11 @@ enum Foo {
#[allow(dead_code)]
struct Bar {
a: usize,
b: usize,
a: u32,
b: u32,
}
fn main() {
let _val: Option<(usize, Foo)> =
unsafe { std::mem::transmute::<_, Option<(usize, Foo)>>(Bar { a: 3, b: 3 }) };
let _val: Option<(u32, Foo)> =
unsafe { std::mem::transmute::<_, Option<(u32, Foo)>>(Bar { a: 3, b: 3 }) };
}

View file

@ -1,6 +1,6 @@
//@ run-fail
//@ compile-flags: -C debug-assertions
//@ error-pattern: trying to construct an enum from an invalid value 0x4
//@ error-pattern: trying to construct an enum from an invalid value
#[allow(dead_code)]
#[repr(u16)]
@ -17,5 +17,5 @@ enum Nested {
}
fn main() {
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(4) };
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(u32::MAX) };
}