Skip to content

Commit 4ace9e6

Browse files
authored
Unrolled build for #155450
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.
2 parents 2f201bc + d9c7177 commit 4ace9e6

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

library/core/src/num/uint_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ macro_rules! uint_impl {
866866
/// # Safety
867867
///
868868
/// This results in undefined behavior when
869-
#[doc = concat!("`self + rhs > ", stringify!($SelfT), "::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`,")]
869+
#[doc = concat!("`self + rhs > ", stringify!($SelfT), "::MAX`,")]
870870
/// i.e. when [`checked_add`] would return `None`.
871871
///
872872
/// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked
@@ -1045,7 +1045,7 @@ macro_rules! uint_impl {
10451045
/// # Safety
10461046
///
10471047
/// This results in undefined behavior when
1048-
#[doc = concat!("`self - rhs > ", stringify!($SelfT), "::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`,")]
1048+
#[doc = concat!("`self - rhs < ", stringify!($SelfT), "::MIN`,")]
10491049
/// i.e. when [`checked_sub`] would return `None`.
10501050
///
10511051
/// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked
@@ -1254,7 +1254,7 @@ macro_rules! uint_impl {
12541254
/// # Safety
12551255
///
12561256
/// This results in undefined behavior when
1257-
#[doc = concat!("`self * rhs > ", stringify!($SelfT), "::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`,")]
1257+
#[doc = concat!("`self * rhs > ", stringify!($SelfT), "::MAX`,")]
12581258
/// i.e. when [`checked_mul`] would return `None`.
12591259
///
12601260
/// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked

0 commit comments

Comments
 (0)