Skip to content

Commit 606e73f

Browse files
committed
Make the intention of the miri test more clear
1 parent 81a556b commit 606e73f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tests/fail/uninit/padding-enum.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ fn main() {
1818

1919
// Turns out the discriminant is (currently) stored
2020
// in the 1st pointer, so the second half is padding.
21-
let c = (&p as *const mem::MaybeUninit<E>).byte_add(mem::size_of::<&'static ()>()) as *const u8;
21+
let c = &p as *const _ as *const u8;
22+
let padding_offset = mem::size_of::<&'static ()>();
2223
// Read a padding byte.
23-
let _val = *c.add(0);
24+
let _val = *c.add(padding_offset);
2425
//~^ERROR: uninitialized
2526
}
2627
}

tests/fail/uninit/padding-enum.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> tests/fail/uninit/padding-enum.rs:LL:CC
33
|
4-
LL | let _val = *c.add(0);
5-
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let _val = *c.add(padding_offset);
5+
| ^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

0 commit comments

Comments
 (0)