Skip to content

doc: Document NonNull pointer ABI compatibility#157982

Closed
0xEgao wants to merge 1 commit into
rust-lang:mainfrom
0xEgao:non-null-doc
Closed

doc: Document NonNull pointer ABI compatibility#157982
0xEgao wants to merge 1 commit into
rust-lang:mainfrom
0xEgao:non-null-doc

Conversation

@0xEgao

@0xEgao 0xEgao commented Jun 16, 2026

Copy link
Copy Markdown

It intends to fix #157741

NonNull<T> is already documented in the primitive ABI compatibility docs as ABI-compatible with raw pointers, but its own representation section only mentioned the Option<NonNull<T>> size/alignment guarantee.

This updates the NonNull docs to state directly that NonNull<T> has the same ABI as *mut T,... .
Except for the non-null validity requirement. This makes the guarantee easier to find from the NonNull page itself.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @LawnGnome (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 11 candidates
  • Random selection from 7 candidates

@LawnGnome

Copy link
Copy Markdown
Contributor

Given his comment in #157741:

r? @RalfJung

(feel free to bounce it back if you don't have time)

@rustbot rustbot assigned RalfJung and unassigned LawnGnome Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@theemathas theemathas added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Jun 17, 2026
@workingjubilee

workingjubilee commented Jun 17, 2026

Copy link
Copy Markdown
Member

My (current) understanding of this PR is that it doesn't need an FCP because it is merely improving cross-reference/reiteration of an existing stable guarantee?

@traviscross traviscross added T-lang Relevant to the language team I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Jun 17, 2026
@traviscross

Copy link
Copy Markdown
Contributor

My (current) understanding of this PR is that it doesn't need an FCP because it is merely improving cross-reference/reiteration of an existing stable guarantee?

I see an existing ABI guarantee but not a layout guarantee.

@traviscross traviscross changed the title doc: Document NonNull pointer ABI compatibility doc: Document NonNull pointer layout and ABI compatibility Jun 17, 2026
@0xEgao

0xEgao commented Jun 17, 2026

Copy link
Copy Markdown
Author

My (current) understanding of this PR is that it doesn't need an FCP because it is merely improving cross-reference/reiteration of an existing stable guarantee?

I see an existing ABI guarantee but not a layout guarantee.

Hey i think you're right,Sorry i thought that because it's repr[transparent]. I have removed layout gurantee claim.

@0xEgao 0xEgao changed the title doc: Document NonNull pointer layout and ABI compatibility doc: Document NonNull pointer ABI compatibility Jun 17, 2026
@traviscross traviscross added T-lang Relevant to the language team and removed T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Jun 17, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Thanks for the PR and for your efforts on it. But I'm going to close this. This is already documented where we document guarantees about ABI compatibility. In other places, where we are documenting both layout and ABI compatibility, we sometimes do say both under a Representation section, but documenting only ABI compatibility under Representation would seem wrong. We could fix that by adding a new section for ABI compatibility. But then we also need to fix the guarantee to fully match what's in the ABI compatibility section rather than truncating that guarantee. And we should cross link it.

But it just doesn't seem worth it. There's cost to duplicating our guarantees. We don't consistently duplicate our ABI guarantees outside of the canonical page for that. It seems OK here to just leave it alone.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
@0xEgao 0xEgao deleted the non-null-doc branch June 17, 2026 07:33
@traviscross traviscross assigned traviscross and unassigned RalfJung Jun 17, 2026
@RalfJung

RalfJung commented Jun 23, 2026

Copy link
Copy Markdown
Member

@traviscross we currently have a clear inconsistency between the NonZero docs and the NonNull docs. That is IMO clearly something we should fix. In particular, we want that layout guarantee.

However this PR does not quite do that. @0xEgao I would suggest you make a new PR that focuses on making the docs consistent, i.e. explaining the same things using the same words in both cases.

@0xEgao

0xEgao commented Jun 23, 2026

Copy link
Copy Markdown
Author

@traviscross we currently have a clear inconsistency between the NonZero docs and the NonNull docs. That is IMO clearly something we should fix. In particular, we want that layout guarantee.

However this PR does not quite do that. @0xEgao I would suggest you make a new PR that focuses on making the docs consistent, i.e. explaining the same things using the same words in both cases.

Sure I will create one focusing on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. T-lang Relevant to the language team T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NonNull<T> doesn't guarantee ABI compatibility with *mut T

7 participants