Noratrieb · GitHub

https://docs.rs/zerocopy/latest/zerocopy/struct.Unalign.html states

Unalign<T> has the same size and ABI as T

This is wrong, as the type is #[repr(C, packed)] and not repr(transparent).

The Rust reference about repr(transparent):

This is different than the C representation because a struct with the C representation will always have the ABI of a C struct while, for example, a struct with the transparent representation with a primitive field will have the ABI of the primitive field.

Here's an example of such an ABI mismatch in practice: https://godbolt.org/z/bhP71dnh4

The docs should be relaxed to not promise full ABI compatibility, but only promise what repr(C) promises (which is probably strong enough for most use cases).

Read the original on github.com ↗