rust/tests/compile-fail/unaligned_pointers/reference_to_packed.rs
2020-04-11 11:36:55 +02:00

20 lines
400 B
Rust

// This should fail even without validation/SB
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
#![allow(dead_code, unused_variables)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
let foo = Foo {
x: 42,
y: 99,
};
let p = unsafe { &foo.x };
let i = *p; //~ ERROR memory with alignment 1, but alignment 4 is required
}