Skip to content

Stabilize unchecked nonzero_ops - #164485

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hsanzg:stable-nonzero
Nov 22, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hsanzg:stable-nonzero

Conversation

@hsanzg

@hsanzg hsanzg commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

The original nonzero_ops feature was partly stabilized as nonzero_checked_ops, leaving the NonZero::unchecked_{add,mul} operations feature-gated until their primitive counterparts ({i,u}*::unchecked_{add,mul}) were stabilized. The latter operations were (const) stabilized in 1.79, but the unchecked NonZero operations have stayed in limbo until now. Since there were no other objections apart from primitive stabilization in the tracking issue, I think it's fair to stabilize the unchecked nonzero methods now.

(Newbie question: I added the rustc_const_stable attribute with a const_nonzero_ops feature name; should I use nonzero_ops instead?)

Closes #84186.

API being stabilized

impl NonZero<U> { // `U` is any unsigned integer type.
    pub const unsafe fn unchecked_add(self, other: U) -> Self;
}

impl NonZero<I> { // `I` is any integer type, signed or unsigned.
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self;
}

@rustbot modify labels: +T-libs

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

rustbot commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum

@clarfonthey

Copy link
Copy Markdown
Contributor

@rfcbot merge libs

These seem relatively straightforward now that the zeroable counterparts are stable.

@rust-rfcbot

rust-rfcbot commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

@clarfonthey 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!

cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 17, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

r? clarfonthey

r=me pending FCP.

@rustbot rustbot assigned clarfonthey and unassigned JohnTitor Oct 17, 2026
Comment thread library/core/src/num/nonzero.rs Resolved
@clarfonthey

Copy link
Copy Markdown
Contributor

@rustbot author

(feedback from Mark on safety docs)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 22, 2026
@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

hsanzg added a commit to hsanzg/rust that referenced this pull request Oct 24, 2026
Inequalities like `x > T::MAX` for any integer type `T` in safety
comments implicitly imply to be defined over the "mathematical"
integers, whereas a regular reader may instead understand their `Ord`
meaning (and thus never become possibly satisfied). This discrepancy
was raised on the stabilization PR for the `unchecked` methods on
`NonZero`: rust-lang#164485 (comment).

I think removing the inequalities outright should be ok, because each
safety comment refers to its `checked_*` counterpart. Similar methods
dealing with overflow also do not give explicit bounds; but if you
prefer, I can replace my changes with messages like "This results in
undefined behavior when `x > T::MAX` over the mathematical integers
(without wrapping around)".
@hsanzg

hsanzg commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

The safety comment issue can be solved separately and doesn't block stabilization.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 24, 2026
hsanzg added a commit to hsanzg/rust that referenced this pull request Oct 24, 2026
Inequalities like `x > T::MAX` for any integer type `T` in safety
comments implicitly imply to be defined over the "mathematical"
integers, whereas a regular reader may instead understand their
meaning over `T` (and thus never become possibly satisfied). This
discrepancy was raised on the stabilization PR for the `unchecked`
methods on `NonZero`: rust-lang#164485 (comment).

I think removing the inequalities outright should be ok, because each
safety comment refers to its `checked_*` counterpart. Similar methods
dealing with overflow also do not give explicit bounds; but if you
prefer, I can replace my changes with messages like "This results in
undefined behavior when `x > T::MAX` over the mathematical integers
(without wrapping around)".
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 25, 2026
Remove contradictory inequalities from overflow safety docs

Inequalities like `x > T::MAX` for any integer type `T` in safety comments implicitly imply to be defined over the "mathematical" integers, whereas a regular reader may instead understand their meaning over `T` (and thus never become possibly satisfied). This discrepancy was raised on the stabilization PR for the `unchecked` methods on `NonZero`: rust-lang#164485 (comment).

I think removing the inequalities outright should be ok, because each safety comment refers to its `checked_*` counterpart. Similar methods dealing with overflow also do not give explicit bounds; but if you prefer, I can replace my changes with messages like "This results in undefined behavior when `x > T::MAX` over the mathematical integers (without wrapping around)".
@clarfonthey

Copy link
Copy Markdown
Contributor

The safety comment issue can be solved separately and doesn't block stabilization.

Note that this doesn't block the FCP process, which can take multiple weeks for people to collect checkboxes and then to wait for the mandatory comment period. So, I think it would be valuable to try and get this done before we merge this, so that when it's released it also has accurate documentation.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 25, 2026
Rollup merge of #164846 - hsanzg:overflow-docs, r=jhpratt

Remove contradictory inequalities from overflow safety docs

Inequalities like `x > T::MAX` for any integer type `T` in safety comments implicitly imply to be defined over the "mathematical" integers, whereas a regular reader may instead understand their meaning over `T` (and thus never become possibly satisfied). This discrepancy was raised on the stabilization PR for the `unchecked` methods on `NonZero`: #164485 (comment).

I think removing the inequalities outright should be ok, because each safety comment refers to its `checked_*` counterpart. Similar methods dealing with overflow also do not give explicit bounds; but if you prefer, I can replace my changes with messages like "This results in undefined behavior when `x > T::MAX` over the mathematical integers (without wrapping around)".
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 11, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

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

Comment thread library/core/src/num/nonzero.rs Resolved
The original `nonzero_ops` feature
(rust-lang#84186) was partly stabilized
as `nonzero_checked_ops`, leaving the `NonZero::unchecked_{add,mul}`
operations feature-gated until their primitive counterparts
(`{i,u}*::unchecked_{add,mul}`) were stabilized. The latter operations
were (const) stabilized in 1.79, but the unchecked `NonZero` operations
have stayed in limbo until now.
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels Nov 21, 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.

@clarfonthey

Copy link
Copy Markdown
Contributor

@bors r+ rollup

Thank you!

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ef3b581 has been approved by clarfonthey

It is now in the queue for this repository.

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

Reason for tree closure: repeated failures in dist-x86_64-msvc

@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 Nov 22, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 22, 2026
Stabilize unchecked `nonzero_ops`

The original [`nonzero_ops` feature](rust-lang#84186) was [partly stabilized](rust-lang#97547) as `nonzero_checked_ops`, leaving the `NonZero::unchecked_{add,mul}` operations feature-gated until their primitive counterparts (`{i,u}*::unchecked_{add,mul}`) were stabilized. The latter operations were (const) stabilized in 1.79, but the unchecked `NonZero` operations have stayed in limbo until now. Since there were no other objections apart from primitive stabilization in the tracking issue, I think it's fair to stabilize the unchecked nonzero methods now.

Closes rust-lang#84186.

## API being stabilized

```rust
impl NonZero<U> { // `U` is any unsigned integer type.
    pub const unsafe fn unchecked_add(self, other: U) -> Self;
}

impl NonZero<I> { // `I` is any integer type, signed or unsigned.
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self;
}
```

@rustbot modify labels: +T-libs
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
Rollup of 15 pull requests

Successful merges:

 - #166266 (miri subtree update)
 - #165720 (windows: remove redundant prefix parsing in `PathBuf::_push`)
 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
Stabilize unchecked `nonzero_ops`

The original [`nonzero_ops` feature](rust-lang#84186) was [partly stabilized](rust-lang#97547) as `nonzero_checked_ops`, leaving the `NonZero::unchecked_{add,mul}` operations feature-gated until their primitive counterparts (`{i,u}*::unchecked_{add,mul}`) were stabilized. The latter operations were (const) stabilized in 1.79, but the unchecked `NonZero` operations have stayed in limbo until now. Since there were no other objections apart from primitive stabilization in the tracking issue, I think it's fair to stabilize the unchecked nonzero methods now.

Closes rust-lang#84186.

## API being stabilized

```rust
impl NonZero<U> { // `U` is any unsigned integer type.
    pub const unsafe fn unchecked_add(self, other: U) -> Self;
}

impl NonZero<I> { // `I` is any integer type, signed or unsigned.
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self;
}
```

@rustbot modify labels: +T-libs
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 22, 2026
Stabilize unchecked `nonzero_ops`

The original [`nonzero_ops` feature](rust-lang#84186) was [partly stabilized](rust-lang#97547) as `nonzero_checked_ops`, leaving the `NonZero::unchecked_{add,mul}` operations feature-gated until their primitive counterparts (`{i,u}*::unchecked_{add,mul}`) were stabilized. The latter operations were (const) stabilized in 1.79, but the unchecked `NonZero` operations have stayed in limbo until now. Since there were no other objections apart from primitive stabilization in the tracking issue, I think it's fair to stabilize the unchecked nonzero methods now.

Closes rust-lang#84186.

## API being stabilized

```rust
impl NonZero<U> { // `U` is any unsigned integer type.
    pub const unsafe fn unchecked_add(self, other: U) -> Self;
}

impl NonZero<I> { // `I` is any integer type, signed or unsigned.
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self;
}
```

@rustbot modify labels: +T-libs
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #166266 (miri subtree update)
 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #164878 (Don't require `extern "llvm-intrinsic"` return structs to be `#[repr(packed)]`)
 - #165008 (Support `NonNull` pointers as `asm!` input operands)
 - #165892 (`rustc_builtin_macros` cleanup, part 10)
 - #165930 (Add red-green mark when dumping dep graph. Show DefIds if available)
 - #166280 (std: also mark doctests with skip_unsupported_miri_tests)
 - #166295 (use `cfg!(overflow_checks)` in `overflow_checks` intrinsic instead of `cfg!(debug_assertions)`)
 - #164485 (Stabilize unchecked `nonzero_ops`)
 - #165618 (Implement RangeIntersect on core::range types)
 - #165782 (Make unsafe unknown diagnostic attributes an error again)
 - #165833 (Deallocate with the right provenance on Windows)
 - #165834 (Implement tidy alphabetical --bless on Windows)
 - #165889 (Fix docs of alloc fn: Allocator API stabilized)
 - #165923 (Don't load/store a LLVM aggregate type when returning an array from a generic SIMD intrinsic)
 - #166012 (Added more queries to AdtDef in rustc_public to check for rust language types)
 - #166186 (OpenOptions::append: clarify docs)
 - #166216 (Stop using #![no_core] in profiler_builtins)
 - #166259 (fmt: Improve `Debug` for `FormattingOptions`)
 - #166263 (Show slice split results for empty and singleton slices)
@rust-bors
rust-bors Bot merged commit a3c276d into rust-lang:main Nov 22, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
Rollup merge of #164485 - hsanzg:stable-nonzero, r=clarfonthey

Stabilize unchecked `nonzero_ops`

The original [`nonzero_ops` feature](#84186) was [partly stabilized](#97547) as `nonzero_checked_ops`, leaving the `NonZero::unchecked_{add,mul}` operations feature-gated until their primitive counterparts (`{i,u}*::unchecked_{add,mul}`) were stabilized. The latter operations were (const) stabilized in 1.79, but the unchecked `NonZero` operations have stayed in limbo until now. Since there were no other objections apart from primitive stabilization in the tracking issue, I think it's fair to stabilize the unchecked nonzero methods now.

Closes #84186.

## API being stabilized

```rust
impl NonZero<U> { // `U` is any unsigned integer type.
    pub const unsafe fn unchecked_add(self, other: U) -> Self;
}

impl NonZero<I> { // `I` is any integer type, signed or unsigned.
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self;
}
```

@rustbot modify labels: +T-libs
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.

Tracking Issue for nonzero_ops

8 participants