diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-04-15 12:27:23 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-04-17 14:54:15 +0200 |
| commit | e9f892acc44f37887fe1b9f3039ba6efdfc2154e (patch) | |
| tree | 2189d2d219d31efe706f8b93788ce6730d11f2cb /src/libcore/num | |
| parent | c34fa8b2c58aa891a99da397f317793be69bfdb1 (diff) | |
| download | rust-e9f892acc44f37887fe1b9f3039ba6efdfc2154e.tar.gz rust-e9f892acc44f37887fe1b9f3039ba6efdfc2154e.zip | |
side-step potentially panic'ing negate in `fn abs`.
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/mod.rs | 6 |
1 files changed, 5 insertions, 1 deletions
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 @@ 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`. |
