Skip to content

Commit e745e09

Browse files
authored
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.
2 parents 0352a28 + 4ec0377 commit e745e09

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: library/core/src/num/int_macros.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1533,9 +1533,8 @@ macro_rules! int_impl {
15331533
#[must_use = "this returns the result of the operation, \
15341534
without modifying the original"]
15351535
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
1536-
// Using `&` helps LLVM see that it is the same check made in division.
1537-
if unlikely!((self == Self::MIN) & (rhs == -1)) {
1538-
(0, true)
1536+
if unlikely!(rhs == -1) {
1537+
(0, self == Self::MIN)
15391538
} else {
15401539
(self % rhs, false)
15411540
}
@@ -1565,9 +1564,8 @@ macro_rules! int_impl {
15651564
without modifying the original"]
15661565
#[inline]
15671566
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
1568-
// Using `&` helps LLVM see that it is the same check made in division.
1569-
if unlikely!((self == Self::MIN) & (rhs == -1)) {
1570-
(0, true)
1567+
if unlikely!(rhs == -1) {
1568+
(0, self == Self::MIN)
15711569
} else {
15721570
(self.rem_euclid(rhs), false)
15731571
}

0 commit comments

Comments
 (0)