rust/tests/compile-fail/unaligned_pointers/reference_to_packed.rs

20 lines
400 B
Rust
Raw Normal View History

// This should fail even without validation/SB
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
2017-01-31 10:36:46 +01:00
#![allow(dead_code, unused_variables)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
let foo = Foo {
x: 42,
y: 99,
};
2017-12-05 17:06:03 +01:00
let p = unsafe { &foo.x };
2020-03-08 23:34:54 +01:00
let i = *p; //~ ERROR memory with alignment 1, but alignment 4 is required
2017-06-22 21:01:24 -07:00
}