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 c7714afc4fa26..a056e585fee65 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -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`.