mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-21 14:22:26 +00:00
Force #[repr(C)]
layout to guarantee same offset of union
fields. (#268)
https://rust-lang.github.io/unsafe-code-guidelines/layout/unions.html points out that > [...] the default layout of Rust unions is, in general, > unspecified. > > That is, there are no general guarantees about the offset of the > fields, whether all fields have the same offset, what the call ABI > of the union is, etc. This commit explicitly asks for `#[repr(C)]` layout to guarantee that both fields have the same offeset.
This commit is contained in:
parent
3c42ba7f23
commit
3f42bec539
@ -127,6 +127,7 @@ macro_rules! transmute {
|
|||||||
// since the compiler hedges that the type being borrowed could have interior mutability.
|
// since the compiler hedges that the type being borrowed could have interior mutability.
|
||||||
($srcty:ty; $dstty:ty; $val:expr) => {
|
($srcty:ty; $dstty:ty; $val:expr) => {
|
||||||
{
|
{
|
||||||
|
#[repr(C)]
|
||||||
union Transmute<A, B> {
|
union Transmute<A, B> {
|
||||||
src: ::core::mem::ManuallyDrop<A>,
|
src: ::core::mem::ManuallyDrop<A>,
|
||||||
dst: ::core::mem::ManuallyDrop<B>,
|
dst: ::core::mem::ManuallyDrop<B>,
|
||||||
|
Loading…
Reference in New Issue
Block a user