]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions
authorAlphyr <47725341+a1phyr@users.noreply.github.com>
Sun, 3 Oct 2021 20:44:07 +0000 (22:44 +0200)
committerGitHub <noreply@github.com>
Sun, 3 Oct 2021 20:44:07 +0000 (22:44 +0200)
Co-authored-by: kennytm <kennytm@gmail.com>
library/core/src/num/int_macros.rs

index 5f299687780ef74b275632ef878398d251f15c66..540b7d36625af6cd4dd42b6a36b4e7c131cdb16c 100644 (file)
@@ -501,7 +501,7 @@ pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
             unsafe { intrinsics::unchecked_sub(self, rhs) }
         }
 
-        /// Checked addition with an unsigned integer. Computes `self + rhs`,
+        /// Checked subtraction with an unsigned integer. Computes `self - rhs`,
         /// returning `None` if overflow occurred.
         ///
         /// # Examples
@@ -885,10 +885,7 @@ pub const fn saturating_add(self, rhs: Self) -> Self {
         #[inline]
         pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self {
             // Overflow can only happen at the upper bound
-            match self.checked_add_unsigned(rhs) {
-                Some(x) => x,
-                None => Self::MAX,
-            }
+            self.checked_add_unsigned(rhs).unwrap_or(Self::MAX)
         }
 
         /// Saturating integer subtraction. Computes `self - rhs`, saturating at the
@@ -912,7 +909,7 @@ pub const fn saturating_sub(self, rhs: Self) -> Self {
             intrinsics::saturating_sub(self, rhs)
         }
 
-        /// Saturating substraction with an unsigned integer. Computes `self - rhs`,
+        /// Saturating subtraction with an unsigned integer. Computes `self - rhs`,
         /// saturating at the numeric bounds instead of overflowing.
         ///
         /// # Examples
@@ -931,10 +928,7 @@ pub const fn saturating_sub(self, rhs: Self) -> Self {
         #[inline]
         pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self {
             // Overflow can only happen at the lower bound
-            match self.checked_sub_unsigned(rhs) {
-                Some(x) => x,
-                None => Self::MIN,
-            }
+            self.checked_sub_unsigned(rhs).unwrap_or(Self::MIN)
         }
 
         /// Saturating integer negation. Computes `-self`, returning `MAX` if `self == MIN`
@@ -1133,7 +1127,7 @@ pub const fn wrapping_sub(self, rhs: Self) -> Self {
             intrinsics::wrapping_sub(self, rhs)
         }
 
-        /// Wrapping (modular) substraction with an unsigned integer. Computes
+        /// Wrapping (modular) subtraction with an unsigned integer. Computes
         /// `self - rhs`, wrapping around at the boundary of the type.
         ///
         /// # Examples
@@ -1584,7 +1578,7 @@ pub const fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool) {
 
         /// Calculates `self` - `rhs` with an unsigned `rhs`
         ///
-        /// Returns a tuple of the substraction along with a boolean indicating
+        /// Returns a tuple of the subtraction along with a boolean indicating
         /// whether an arithmetic overflow would occur. If an overflow would
         /// have occurred then the wrapped value is returned.
         ///