]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr_zst.rs
Rollup merge of #101642 - SkiFire13:fix-inplace-collection-leak, r=the8472
[rust.git] / src / tools / miri / tests / fail / unaligned_pointers / unaligned_ptr_zst.rs
1 // This should fail even without validation
2 // Some optimizations remove ZST accesses, thus masking this UB.
3 //@compile-flags: -Zmir-opt-level=0 -Zmiri-disable-validation
4
5 fn main() {
6     // Try many times as this might work by chance.
7     for i in 0..10 {
8         let x = i as u8;
9         let x = &x as *const _ as *const [u32; 0];
10         // This must fail because alignment is violated. Test specifically for loading ZST.
11         let _x = unsafe { *x }; //~ERROR: alignment 4 is required
12     }
13 }