about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/num/uint_macros.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index 5a65f77a879..96375b82582 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -1037,10 +1037,13 @@ macro_rules! uint_impl {
                       without modifying the original"]
         #[inline]
         pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self {
-            if rhs >= 0 {
-                self.saturating_add(rhs as Self)
+            let (res, overflow) = self.overflowing_add(rhs as Self);
+            if overflow == (rhs < 0) {
+                res
+            } else if overflow {
+                Self::MAX
             } else {
-                self.saturating_sub(rhs.unsigned_abs())
+                0
             }
         }