rust/tests/compile-fail/reference_to_packed.rs
Ralf Jung 72664e42aa No longer check aligment and non-NULLness on &
This breaks creating unaligned raw pointers via `&packed.field as *const _`, which needs to be legal.
Also it doesn't seem like LLVM still relies on this, see
* https://github.com/solson/miri/issues/244#issuecomment-315563640
* https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430/16

We probably want to handle this invariant like the others that validation is concerned with, and only
check it on function boundaries for now.
2017-07-19 11:28:35 -07:00

17 lines
282 B
Rust

#![allow(dead_code, unused_variables)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
let foo = Foo {
x: 42,
y: 99,
};
let p = &foo.x;
let i = *p; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required
}