rust/tests/compile-fail/reference_to_packed_unsafe.rs

17 lines
313 B
Rust
Raw Normal View History

2017-01-31 03:36:46 -06:00
#![allow(dead_code, unused_variables)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
let foo = Foo {
x: 42,
y: 99,
};
let p: *const i32 = &foo.x;
let x = unsafe { *p + foo.x }; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required
}