]> git.lizzy.rs Git - rust.git/commitdiff
side-step potentially panic'ing negate in `fn abs`.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Wed, 15 Apr 2015 10:27:23 +0000 (12:27 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 17 Apr 2015 12:54:15 +0000 (14:54 +0200)
src/libcore/num/mod.rs

index c7714afc4fa263b7435b2e8880fa33880c0cb977..a056e585fee65644beeba413ba9a5accaebb9023 100644 (file)
@@ -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`.