Rollup merge of #118397 - Zalathar:nonzero, r=WaffleLapkin

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

While looking at #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.
This commit is contained in:
Matthias Krüger 2023-11-28 09:28:39 +01:00 committed by GitHub
commit 4f3ee302b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
//
@ -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
//