]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/unaligned_pointers/alignment.rs
forgot to add alignment test loop in one test
[rust.git] / tests / compile-fail / unaligned_pointers / alignment.rs
1 // error-pattern: but alignment 4 is required
2
3 fn main() {
4     // No retry needed, this fails reliably.
5
6     let mut x = [0u8; 20];
7     let x_ptr: *mut u8 = x.as_mut_ptr();
8     // At least one of these is definitely unaligned.
9     unsafe {
10         *(x_ptr as *mut u32) = 42;
11         *(x_ptr.add(1) as *mut u32) = 42;
12     }
13 }