]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/pointer_partial_overwrite.rs
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
[rust.git] / src / tools / miri / tests / fail / pointer_partial_overwrite.rs
1 // Make sure we find these even with many checks disabled.
2 //@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3
4 // Test what happens when we overwrite parts of a pointer.
5 // Also see <https://github.com/rust-lang/miri/issues/2181>.
6
7 fn main() {
8     let mut p = &42;
9     unsafe {
10         let ptr: *mut _ = &mut p;
11         *(ptr as *mut u8) = 123; // if we ever support 8 bit pointers, this is gonna cause
12         // "attempted to interpret some raw bytes as a pointer address" instead of
13         // "attempted to read undefined bytes"
14     }
15     let x = *p; //~ ERROR: this operation requires initialized memory
16     panic!("this should never print: {}", x);
17 }