side-step potentially panic'ing negate in fn abs.
This commit is contained in:
parent
c34fa8b2c5
commit
e9f892acc4
1 changed files with 5 additions and 1 deletions
|
|
@ -1321,7 +1321,11 @@ macro_rules! int_impl {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> $T {
|
||||
if self.is_negative() { -self } else { self }
|
||||
if self.is_negative() {
|
||||
self.wrapping_neg()
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a number representing sign of `self`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue