From e9f892acc44f37887fe1b9f3039ba6efdfc2154e Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 15 Apr 2015 12:27:23 +0200 Subject: [PATCH] side-step potentially panic'ing negate in `fn abs`. --- src/libcore/num/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c7714afc4fa..a056e585fee 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1321,7 +1321,11 @@ pub fn pow(self, mut exp: u32) -> $T { #[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`.