Skip to content

Apparent contradiction between nomicon and reference docs for ZST pointers #198

Open
@Lucretiel

Description

@Lucretiel

There's a passage of the nomicon that reads:

So if the allocator API doesn't support zero-sized allocations, what on earth do we store as our allocation? Unique::empty() of course! Almost every operation with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs to be considered to store or load them. This actually extends to ptr::read and ptr::write: they won't actually look at the pointer at all. As such we never need to change the pointer.

However, the docs for ptr::read state:

Note that even if T has size 0, the pointer must be non-NULL and properly aligned.

Is this a contradiction? The former passage states that ptr::read for a ZST is a "no-op" that "won't actually look at the pointer at all", which would seem to imply it doesn't matter what data you pass to it, but the latter passage states that it DOES matter, you must pass an aligned, non-null pointer.

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