about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-05 12:52:45 -0700
committerGitHub <noreply@github.com>2021-10-05 12:52:45 -0700
commite745e098c45771c5d411f55b72efa96cbeb9aca6 (patch)
treebbffeab68ab88fc5a69fa98772cdb59f3c9b1e6f
parent0352a2820d65159c19e323b519c147d134fbf9f0 (diff)
parent4ec0377d6a9118b41df4fb587dc0b7d1fc53656f (diff)
downloadrust-e745e098c45771c5d411f55b72efa96cbeb9aca6.tar.gz
rust-e745e098c45771c5d411f55b72efa96cbeb9aca6.zip
Rollup merge of #89351 - tspiteri:wrapping_rem, r=dtolnay
for signed wrapping remainder, do not compare lhs with MIN

Since the wrapped remainder is going to be 0 for all cases when the rhs is -1, there is no need to compare the lhs with MIN.
-rw-r--r--library/core/src/num/int_macros.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs
index f1dcdf2c1aa..9d46948ce02 100644
--- a/library/core/src/num/int_macros.rs
+++ b/library/core/src/num/int_macros.rs
@@ -1533,9 +1533,8 @@ macro_rules! int_impl {
         #[must_use = "this returns the result of the operation, \
                       without modifying the original"]
         pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
-            // Using `&` helps LLVM see that it is the same check made in division.
-            if unlikely!((self == Self::MIN) & (rhs == -1)) {
-                (0, true)
+            if unlikely!(rhs == -1) {
+                (0, self == Self::MIN)
             } else {
                 (self % rhs, false)
             }
@@ -1565,9 +1564,8 @@ macro_rules! int_impl {
                       without modifying the original"]
         #[inline]
         pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
-            // Using `&` helps LLVM see that it is the same check made in division.
-            if unlikely!((self == Self::MIN) & (rhs == -1)) {
-                (0, true)
+            if unlikely!(rhs == -1) {
+                (0, self == Self::MIN)
             } else {
                 (self.rem_euclid(rhs), false)
             }