Remove unnecessary safety conditions related to unchecked uint arithmetic#155450
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Apr 18, 2026
Merged
Remove unnecessary safety conditions related to unchecked uint arithmetic#155450rust-bors[bot] merged 1 commit intorust-lang:mainfrom
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
Nice catch. @bors r+ rollup |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Apr 18, 2026
Remove unnecessary safety conditions related to unchecked uint arithmetic Improve the safety documentation of three unsafe APIs related to unsigned integer arithmetic. - [unchecked_add](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_add): It is impossible for `self + rhs < usize::MIN`. - [unchecked_sub](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_sub): It is impossible for `self - rhs > usize::MAX`. - [unchecked_mul](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_mul): It is impossible for `self * rhs < usize::MIN`. The examples use `usize` for demonstration. All unsigned integer types suffer from the same issue because their APIs are generated by the same macro `uint_impl`, and fixing the macro documentation will fix them all.
This was referenced Apr 18, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Apr 18, 2026
Rollup of 12 pull requests Successful merges: - #147811 (naked functions: respect `function-sections`) - #154935 (Add Sized supertrait for CoerceUnsized and DispatchFromDyn) - #139690 (`impl Default for RepeatN`) - #153511 (`std::any::TypeId`: remove misplaced "and" in `Unique<T>` example) - #154943 (Move recursion out of `MatchPairTree::for_pattern` helpers ) - #155295 (Fix misleading "borrowed data escapes outside of function" diagnostic) - #155427 (ptr: update text in intro text to one in with_addr doc) - #155428 (Fix ICE in borrowck mutability suggestion with multi-byte ref sigil) - #155435 (rustdoc: Fix `redundant_explicit_links` incorrectly firing (or not firing) under certain scenarios) - #155450 (Remove unnecessary safety conditions related to unchecked uint arithmetic) - #155454 (docs: Fix typo in std/src/thready/scoped.rs) - #155467 (`std::error::Request`: clean up documentation)
rust-timer
added a commit
that referenced
this pull request
Apr 18, 2026
Rollup merge of #155450 - safer-rust:fix-doc2, r=jhpratt Remove unnecessary safety conditions related to unchecked uint arithmetic Improve the safety documentation of three unsafe APIs related to unsigned integer arithmetic. - [unchecked_add](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_add): It is impossible for `self + rhs < usize::MIN`. - [unchecked_sub](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_sub): It is impossible for `self - rhs > usize::MAX`. - [unchecked_mul](https://doc.rust-lang.org/nightly/core/primitive.usize.html#method.unchecked_mul): It is impossible for `self * rhs < usize::MIN`. The examples use `usize` for demonstration. All unsigned integer types suffer from the same issue because their APIs are generated by the same macro `uint_impl`, and fixing the macro documentation will fix them all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve the safety documentation of three unsafe APIs related to unsigned integer arithmetic.
self + rhs < usize::MIN.self - rhs > usize::MAX.self * rhs < usize::MIN.The examples use
usizefor demonstration. All unsigned integer types suffer from the same issue because their APIs are generated by the same macrouint_impl, and fixing the macro documentation will fix them all.