about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlphyr <47725341+a1phyr@users.noreply.github.com>2021-07-30 12:11:18 +0200
committerBenoƮt du Garreau <bdgdlm@outlook.com>2021-10-01 19:08:13 +0200
commitab9f8a0b593a832f98188cd755bd467eeb9416d4 (patch)
treea80cee36578b6ac10e0a9d8d1b98d159b748bf38
parentfe11483afa90628106971993049b4fd2f0dae6fc (diff)
downloadrust-ab9f8a0b593a832f98188cd755bd467eeb9416d4.tar.gz
rust-ab9f8a0b593a832f98188cd755bd467eeb9416d4.zip
Apply suggestion for `overflowing_add_signed`
Co-authored-by: kennytm <kennytm@gmail.com>
-rw-r--r--library/core/src/num/uint_macros.rs7
1 files changed, 2 insertions, 5 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index 67d72a17135..2c4097a30a1 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -1528,11 +1528,8 @@ macro_rules! uint_impl {
                       without modifying the original"]
         #[inline]
         pub const fn overflowing_add_signed(self, rhs: $SignedT) -> (Self, bool) {
-            if rhs >= 0 {
-                self.overflowing_add(rhs as Self)
-            } else {
-                self.overflowing_sub(rhs.unsigned_abs())
-            }
+            let (res, overflowed) = self.overflowing_add(rhs as Self);
+            (res, overflowed ^ (rhs < 0))
         }
 
         /// Calculates `self` - `rhs`