We now track in the lvalue whether what we computed is expected to be aligend or not, and then set some state in the memory system accordingly to make it (not) do alignment checks
23 lines
379 B
Rust
23 lines
379 B
Rust
#[repr(packed)]
|
|
struct S {
|
|
a: i32,
|
|
b: i64,
|
|
}
|
|
|
|
fn main() {
|
|
let mut x = S {
|
|
a: 42,
|
|
b: 99,
|
|
};
|
|
let a = x.a;
|
|
let b = x.b;
|
|
assert_eq!(a, 42);
|
|
assert_eq!(b, 99);
|
|
// can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
|
|
assert_eq!({x.a}, 42);
|
|
assert_eq!({x.b}, 99);
|
|
|
|
x.b = 77;
|
|
assert_eq!({x.b}, 77);
|
|
}
|