Merge pull request #3772 from RossSmyth/Layouts

Fix some layout reprs
This commit is contained in:
Brian Carroll 2022-08-14 10:50:48 +01:00 committed by GitHub
commit fe0dad1136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View file

@ -152,6 +152,7 @@ impl Symbol {
}
pub const fn to_ne_bytes(self) -> [u8; 8] {
// repr(packed(4)) is repr(c), and with the fields as defined will not having padding.
unsafe { std::mem::transmute(self) }
}

View file

@ -66,6 +66,7 @@ struct ErrorTypeState {
recursive_tag_unions_seen: Vec<Variable>,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
struct SubsHeader {
utable: u64,
@ -99,10 +100,12 @@ impl SubsHeader {
}
fn to_array(self) -> [u8; std::mem::size_of::<Self>()] {
// Safety: With repr(c) all fields are in order and properly aligned without padding.
unsafe { std::mem::transmute(self) }
}
fn from_array(array: [u8; std::mem::size_of::<Self>()]) -> Self {
// Safety: With repr(c) all fields are in order and properly aligned without padding.
unsafe { std::mem::transmute(array) }
}
}