fmt
This commit is contained in:
parent
cf1ef1300e
commit
0d5fdcca6c
2 changed files with 24 additions and 20 deletions
|
@ -23,13 +23,15 @@ impl PackedSized {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() { unsafe {
|
||||
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
|
||||
let p = p.unsize() as *const PackedUnsized;
|
||||
// Make sure the size computation does *not* think there is
|
||||
// any padding in front of the `d` field.
|
||||
assert_eq!(mem::size_of_val_raw(p), 1 + 4*4);
|
||||
// And likewise for the offset computation.
|
||||
let d = std::ptr::addr_of!((*p).d);
|
||||
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
|
||||
} }
|
||||
fn main() {
|
||||
unsafe {
|
||||
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
|
||||
let p = p.unsize() as *const PackedUnsized;
|
||||
// Make sure the size computation does *not* think there is
|
||||
// any padding in front of the `d` field.
|
||||
assert_eq!(mem::size_of_val_raw(p), 1 + 4 * 4);
|
||||
// And likewise for the offset computation.
|
||||
let d = std::ptr::addr_of!((*p).d);
|
||||
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,15 @@ impl PackedSized {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() { unsafe {
|
||||
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
|
||||
let p = p.unsize() as *const PackedUnsized;
|
||||
// Make sure the size computation correctly adds exact 1 byte of padding
|
||||
// in front of the `d` field.
|
||||
assert_eq!(mem::size_of_val_raw(p), 1 + 1 + 4*4);
|
||||
// And likewise for the offset computation.
|
||||
let d = std::ptr::addr_of!((*p).d);
|
||||
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
|
||||
} }
|
||||
fn main() {
|
||||
unsafe {
|
||||
let p = PackedSized { f: 0, d: [1, 2, 3, 4] };
|
||||
let p = p.unsize() as *const PackedUnsized;
|
||||
// Make sure the size computation correctly adds exact 1 byte of padding
|
||||
// in front of the `d` field.
|
||||
assert_eq!(mem::size_of_val_raw(p), 1 + 1 + 4 * 4);
|
||||
// And likewise for the offset computation.
|
||||
let d = std::ptr::addr_of!((*p).d);
|
||||
assert_eq!(d.cast::<u32>().read_unaligned(), 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue