Skip to content

Commit

Permalink
Unrolled build for rust-lang#118397
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#118397 - Zalathar:nonzero, r=WaffleLapkin

Fix comments for unsigned non-zero `checked_add`, `saturating_add`

While looking at rust-lang#118313, I happened to notice that two of the expanded comments appear to be slightly inaccurate.

For these two methods, `other` is an ordinary unsigned integer, so it can be zero.

Since the sum of non-zero and zero is always non-zero, the safety argument holds even when `other` is zero.
  • Loading branch information
rust-timer authored Nov 28, 2023
2 parents e06c94d + 00d5f18 commit 761efba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ macro_rules! nonzero_unsigned_operations {
if let Some(result) = self.get().checked_add(other) {
// SAFETY:
// - `checked_add` returns `None` on overflow
// - `self` and `other` are non-zero
// - `self` is non-zero
// - the only way to get zero from an addition without overflow is for both
// sides to be zero
//
Expand Down Expand Up @@ -393,7 +393,7 @@ macro_rules! nonzero_unsigned_operations {
pub const fn saturating_add(self, other: $Int) -> $Ty {
// SAFETY:
// - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
// - `self` and `other` are non-zero
// - `self` is non-zero
// - the only way to get zero from an addition without overflow is for both
// sides to be zero
//
Expand Down

0 comments on commit 761efba

Please sign in to comment.