Skip to content

Commit 8c49486

Browse files
committed
Clean up const-hack from rust-lang#63786
1 parent f6faf0b commit 8c49486

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/libcore/num/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1416,18 +1416,14 @@ $EndFeature, "
14161416
```"),
14171417
#[stable(feature = "no_panic_abs", since = "1.13.0")]
14181418
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
1419+
#[allow_internal_unstable(const_if_match)]
14191420
#[inline]
14201421
pub const fn wrapping_abs(self) -> Self {
1421-
// sign is -1 (all ones) for negative numbers, 0 otherwise.
1422-
let sign = self >> ($BITS - 1);
1423-
// For positive self, sign == 0 so the expression is simply
1424-
// (self ^ 0).wrapping_sub(0) == self == abs(self).
1425-
//
1426-
// For negative self, self ^ sign == self ^ all_ones.
1427-
// But all_ones ^ self == all_ones - self == -1 - self.
1428-
// So for negative numbers, (self ^ sign).wrapping_sub(sign) is
1429-
// (-1 - self).wrapping_sub(-1) == -self == abs(self).
1430-
(self ^ sign).wrapping_sub(sign)
1422+
if self.is_negative() {
1423+
self.wrapping_neg()
1424+
} else {
1425+
self
1426+
}
14311427
}
14321428
}
14331429

0 commit comments

Comments
 (0)