Skip to content

Document that null is 0 #116895

Closed
Closed

Description

@joshlf

This has come up in two places recently: #115333 (comment) and #116675 (comment).

We should do the following:

  • On ptr::null(), document that ptr::null() is equivalent to 0usize as *const _
  • Either before or after it lands, update the text in #116675 to document that "allocated objects" cannot contain the 0 address (alternatively, if that PR lands with text that says that an allocated object cannot contain the "null" address, update the text to mention that null is equal to 0)

Are there other places we should update too?

cc @the8472 @tmandry @RalfJung

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 18, 2023
  2. added
    T-libs-api[DEPRECATED; DO NOT USE]
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-opsemRelevant to the opsem team
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 19, 2023
  3. Noratrieb commented on Oct 19, 2023

    @Noratrieb
    Member
  4. RalfJung commented on Oct 20, 2023

    @RalfJung
    Member

    document that ptr::null() is equivalent to 0usize as *const _

    Int-to-ptr casts are terrible, I'd rather not do that. In fact these two are not equivalent for Miri (but that might be a Miri limitation, int2ptr is just hard or impossible to handle precisely for a tool like Miri).

    We should say that it returns a pointer whose address is 0, but we shouldn't commit to which provenance it has.

  5. RalfJung commented on Oct 20, 2023

    @RalfJung
    Member

    #116988 adds the docs for this.

  6. added a commit that references this issue on Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-api[DEPRECATED; DO NOT USE]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