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.
This commit is contained in:
Manish Goregaokar 2021-10-05 12:52:45 -07:00 committed by GitHub
commit e745e098c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1533,9 +1533,8 @@ pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
#[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 @@ pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
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)
}