Skip to content

Unalign ABI promises are wrong #164

@Noratrieb

Description

@Noratrieb

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions