1
Fork 0

Make the intention of the miri test more clear

This commit is contained in:
Adwin White 2024-09-19 16:49:39 +08:00
parent c4574cba3b
commit 937b09b389
2 changed files with 5 additions and 4 deletions

View file

@ -18,9 +18,10 @@ fn main() {
// Turns out the discriminant is (currently) stored
// in the 1st pointer, so the second half is padding.
let c = (&p as *const mem::MaybeUninit<E>).byte_add(mem::size_of::<&'static ()>()) as *const u8;
let c = &p as *const _ as *const u8;
let padding_offset = mem::size_of::<&'static ()>();
// Read a padding byte.
let _val = *c.add(0);
let _val = *c.add(padding_offset);
//~^ERROR: uninitialized
}
}

View file

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