Skip to content

Document NonNull layout guarantees#158325

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
0xEgao:docs-non-null
Jul 13, 2026
Merged

Document NonNull layout guarantees#158325
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
0xEgao:docs-non-null

Conversation

@0xEgao

@0xEgao 0xEgao commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

View all comments

As discussed here
Fixes #157741

This updates the NonNull layout docs to match the structure and wording used by NonZero.

  • adds the missing NonNull<T> layout and validity wording, and documents that Option<NonNull<T>> is compatible with *mut T, including in FFI.

r? @RalfJung

@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 23, 2026
@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @RalfJung (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

@0xEgao

0xEgao commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot review

@RalfJung

Copy link
Copy Markdown
Member

No worries, this is in my queue. The queue is just particularly long right now since I was traveling for 2 weeks and came back to around 300 emails in my inbox. It takes a while to go through all that.

@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown
Member

Cc @rust-lang/opsem -- but I think there's nothing new here, we already document the same ABI compatibility in the fn ptr section. Makes sense to me to also have it on the type, like we do for NonZero*.

Thanks @0xEgao!
@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8f66cfd has been approved by RalfJung

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 2, 2026
@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown
Member

@bors r-
Hm, actually, I think we didn't spell out this layout anywhere before. Though giving an ABI guarantee without a layout guarantee makes very little sense. But still, let's go the official route.
@rfcbot fcp merge opsem

Cc @rust-lang/lang in case you have an opinion/concern

@rust-rfcbot

rust-rfcbot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@RalfJung has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 2, 2026
@rust-rfcbot rust-rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jul 2, 2026
@rust-bors

rust-bors Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 2, 2026
@rust-rfcbot rust-rfcbot added the disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. label Jul 2, 2026
@RalfJung RalfJung added S-waiting-on-t-opsem Status: Awaiting decision from T-opsem and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 2, 2026
@scottmcm

scottmcm commented Jul 2, 2026

Copy link
Copy Markdown
Member

Yup, seems entirely non-controversial 👍

Comment thread library/core/src/ptr/non_null.rs Outdated
///
/// `NonNull<T>` is guaranteed to have the same layout and bit validity as `*mut T`
/// with the exception that a null pointer is invalid.
/// `Option<NonNull<T>>` is guaranteed to be compatible with `*mut T`, including in

@joshlf joshlf Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// `Option<NonNull<T>>` is guaranteed to be compatible with `*mut T`, including in
/// `Option<NonNull<T>>` is guaranteed to be ABI-compatible with `*mut T`, including in

Does the word "compatible" on its own have a well-defined meaning?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but if we change this we should also change it for NonZero*.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i think it's better to change that in both cases

@scottmcm

scottmcm commented Jul 2, 2026

Copy link
Copy Markdown
Member

Pondering: when we're talking ABI-compatibility in signatures, how do we square LLVM attributes like nonnull (or range on NonZero<_>) with that? If I write a signature for it with a restriction like that, does it affect others who declare the extern differently?

@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown
Member

I think you're thinking about #46188 ?
There's nothing new in the regard in this PR though (the NonZero* types would have the same problems, if there are any), so if you think there's a problem here, it's probably better to create a new thread/issue somewhere else.

@rust-rfcbot rust-rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jul 2, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@rust-rfcbot rust-rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jul 2, 2026
@0xEgao
0xEgao requested a review from RalfJung July 6, 2026 07:42
@0xEgao
0xEgao requested a review from joshlf July 6, 2026 07:42
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2026
@RalfJung RalfJung added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-t-opsem Status: Awaiting decision from T-opsem labels Jul 8, 2026

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me on the wording, we just need to wait until FCP passes. :)

View changes since this review

@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 12, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@RalfJung

Copy link
Copy Markdown
Member

@bors r+ rollup

Thanks all :)

@rust-bors

rust-bors Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📋 This PR cannot be approved because it currently has the following label: S-waiting-on-fcp.

@RalfJung RalfJung removed the S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. label Jul 13, 2026
@RalfJung

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 74c99d9 has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 13, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 13, 2026
Document NonNull layout guarantees

As discussed [here](rust-lang#157982 (comment))
Fixes rust-lang#157741

This updates the `NonNull` layout docs to match the structure and wording used by `NonZero`.

- adds the missing `NonNull<T>` layout and validity wording, and documents that `Option<NonNull<T>>` is compatible with `*mut T`, including in FFI.

r? @RalfJung
rust-bors Bot pushed a commit that referenced this pull request Jul 13, 2026
Rollup of 11 pull requests

Successful merges:

 - #159210 (`rust-analyzer` subtree update)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #159205 (bootstrap: Replace `ShouldRun::crates` with `crate_or_deps_filtered`)
 - #159208 (Fix `attr_on_non_tail_expr` typo)
 - #157524 (Fix relative paths in private import suggestions)
 - #158325 (Document NonNull layout guarantees)
 - #158882 (enable `do_not_recommend` attr for method call errors in current solver)
 - #158982 (Pretty-print MIR user types too.)
 - #159069 (Add codegen test for constant returns after local use)
 - #159163 (rustc_target: Add acquire-release to implied features of v8)
 - #159201 (borrowck: Represent 'best blame constraint' as index into `Vec<OutlivesConstraint>`)
rust-bors Bot pushed a commit that referenced this pull request Jul 13, 2026
Rollup of 11 pull requests

Successful merges:

 - #159210 (`rust-analyzer` subtree update)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #159205 (bootstrap: Replace `ShouldRun::crates` with `crate_or_deps_filtered`)
 - #159208 (Fix `attr_on_non_tail_expr` typo)
 - #157524 (Fix relative paths in private import suggestions)
 - #158325 (Document NonNull layout guarantees)
 - #158882 (enable `do_not_recommend` attr for method call errors in current solver)
 - #158982 (Pretty-print MIR user types too.)
 - #159069 (Add codegen test for constant returns after local use)
 - #159163 (rustc_target: Add acquire-release to implied features of v8)
 - #159201 (borrowck: Represent 'best blame constraint' as index into `Vec<OutlivesConstraint>`)
@rust-bors
rust-bors Bot merged commit 063c692 into rust-lang:main Jul 13, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 13, 2026
rust-timer added a commit that referenced this pull request Jul 13, 2026
Rollup merge of #158325 - 0xEgao:docs-non-null, r=RalfJung

Document NonNull layout guarantees

As discussed [here](#157982 (comment))
Fixes #157741

This updates the `NonNull` layout docs to match the structure and wording used by `NonZero`.

- adds the missing `NonNull<T>` layout and validity wording, and documents that `Option<NonNull<T>>` is compatible with `*mut T`, including in FFI.

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants