Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that null is 0 #116895

Closed
joshlf opened this issue Oct 18, 2023 · 3 comments · Fixed by #116988
Closed

Document that null is 0 #116895

joshlf opened this issue Oct 18, 2023 · 3 comments · Fixed by #116988
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team

Comments

@joshlf
Copy link
Contributor

joshlf commented Oct 18, 2023

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 18, 2023
@fmease fmease added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-opsem Relevant to the opsem team and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 19, 2023
@Nilstrieb
Copy link
Member

@RalfJung
Copy link
Member

RalfJung commented Oct 20, 2023

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.

@RalfJung
Copy link
Member

#116988 adds the docs for this.

@bors bors closed this as completed in b049093 Nov 6, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Nov 15, 2023
document that the null pointer has the 0 address

Fixes rust-lang/rust#116895

Will need t-lang FCP, but I think this is fairly uncontroversial -- there's probably already tons of code out there that relies on this.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
document that the null pointer has the 0 address

Fixes rust-lang/rust#116895

Will need t-lang FCP, but I think this is fairly uncontroversial -- there's probably already tons of code out there that relies on this.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
document that the null pointer has the 0 address

Fixes rust-lang/rust#116895

Will need t-lang FCP, but I think this is fairly uncontroversial -- there's probably already tons of code out there that relies on this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants