rust/tests/compile-fail/unaligned_pointers/reference_to_packed.rs
2022-05-25 18:26:33 +00:00

22 lines
480 B
Rust

// This should fail even without validation/SB
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
#![allow(dead_code, unused_variables, unaligned_references)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
for _ in 0..10 { // Try many times as this might work by chance.
let foo = Foo {
x: 42,
y: 99,
};
let p = &foo.x;
let i = *p; //~ERROR alignment 4 is required
}
}