Skip to content

Commit b4e68e2

Browse files
committed
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.
1 parent 6268d0a commit b4e68e2

6 files changed

+14
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
3-
//@ error-pattern: trying to construct an enum from an invalid value 0x10000
3+
//@ error-pattern: trying to construct an enum from an invalid value
44

55
#[allow(dead_code)]
66
#[repr(u32)]
@@ -11,10 +11,9 @@ enum Foo {
1111

1212
#[allow(dead_code)]
1313
struct Bar {
14-
a: u16,
15-
b: u16,
14+
a: u32,
1615
}
1716

1817
fn main() {
19-
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 1 }) };
18+
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 3 }) };
2019
}

tests/ui/mir/enum/convert_non_enum_ok.rs renamed to tests/ui/mir/enum/convert_non_integer_ok.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ enum Foo {
1010

1111
#[allow(dead_code)]
1212
struct Bar {
13-
a: u16,
14-
b: u16,
13+
a: u32,
1514
}
1615

1716
fn main() {
18-
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 0 }) };
19-
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1, b: 0 }) };
17+
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0 }) };
18+
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1 }) };
2019
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
3-
//@ error-pattern: trying to construct an enum from an invalid value 0x3
3+
//@ error-pattern: trying to construct an enum from an invalid value
44

55
#[allow(dead_code)]
6+
#[repr(u32)]
67
enum Foo {
78
A,
89
B,
910
}
1011

1112
#[allow(dead_code)]
1213
struct Bar {
13-
a: usize,
14-
b: usize,
14+
a: u32,
15+
b: u32,
1516
}
1617

1718
fn main() {
18-
let _val: Option<(usize, Foo)> =
19-
unsafe { std::mem::transmute::<_, Option<(usize, Foo)>>(Bar { a: 3, b: 3 }) };
19+
let _val: Option<(u32, Foo)> =
20+
unsafe { std::mem::transmute::<_, Option<(u32, Foo)>>(Bar { a: 3, b: 3 }) };
2021
}

tests/ui/mir/enum/with_niche_int_break.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
3-
//@ error-pattern: trying to construct an enum from an invalid value 0x4
3+
//@ error-pattern: trying to construct an enum from an invalid value
44

55
#[allow(dead_code)]
66
#[repr(u16)]
@@ -17,5 +17,5 @@ enum Nested {
1717
}
1818

1919
fn main() {
20-
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(4) };
20+
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(u32::MAX) };
2121
}

0 commit comments

Comments
 (0)