rust/tests/compile-fail/reference_to_packed.rs
2017-12-05 17:06:03 +01:00

20 lines
378 B
Rust

// This should fail even without validation
// compile-flags: -Zmir-emit-validate=0
#![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 tried to access memory with alignment 1, but alignment 4 is required
}