Skip to content

Commit 00d5f18

Browse files
committed
Fix comments for unsigned non-zero checked_add, saturating_add
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.
1 parent 49b3924 commit 00d5f18

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/core/src/num/nonzero.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ macro_rules! nonzero_unsigned_operations {
355355
if let Some(result) = self.get().checked_add(other) {
356356
// SAFETY:
357357
// - `checked_add` returns `None` on overflow
358-
// - `self` and `other` are non-zero
358+
// - `self` is non-zero
359359
// - the only way to get zero from an addition without overflow is for both
360360
// sides to be zero
361361
//
@@ -393,7 +393,7 @@ macro_rules! nonzero_unsigned_operations {
393393
pub const fn saturating_add(self, other: $Int) -> $Ty {
394394
// SAFETY:
395395
// - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
396-
// - `self` and `other` are non-zero
396+
// - `self` is non-zero
397397
// - the only way to get zero from an addition without overflow is for both
398398
// sides to be zero
399399
//

0 commit comments

Comments
 (0)