rust/tests/fail/unaligned_pointers/alignment.rs

15 lines
390 B
Rust
Raw Normal View History

// normalize-stderr-test: "\| +\^+" -> "| ^"
2016-07-06 04:19:24 -05:00
fn main() {
// No retry needed, this fails reliably.
2016-07-06 04:19:24 -05:00
let mut x = [0u8; 20];
2020-04-13 10:51:22 -05:00
let x_ptr: *mut u8 = x.as_mut_ptr();
#[rustfmt::skip]
2016-07-06 04:19:24 -05:00
unsafe {
// At least one of these is definitely unaligned.
*(x_ptr as *mut u32) = 42; *(x_ptr.add(1) as *mut u32) = 42;
//~^ ERROR: but alignment 4 is required
};
2016-07-06 04:19:24 -05:00
}