rust/tests/run-pass/packed_struct.rs

23 lines
379 B
Rust
Raw Normal View History

2017-01-30 02:44:52 -06:00
#[repr(packed)]
struct S {
a: i32,
b: i64,
}
fn main() {
let mut x = S {
2017-01-30 02:44:52 -06:00
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);
2017-01-30 02:44:52 -06:00
}