Skip to content

std::pointer::Nonnull should guarantee ABI compatibility for non-null pointer values #145989

@jacobsa

Description

@jacobsa

Can we rely on NonNull<T> having the same representation as *mut T for all non-null values of that type? In particular, can we rely on e.g. NonNull<std::ffi::c_void> being ABI compatible with C void* for non-null pointers?

It seems pretty likely that this should work, but the documentation doesn't guarantee it as far as I can see. The representation documentation for Nonnull only says that an extra byte won't be used for the discriminant in Option<Nonnull<T>>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions