Skip to content

Commit a96e1f8

Browse files
committed
---
yaml --- r: 212646 b: refs/heads/beta c: 9febb89 h: refs/heads/master v: v3
1 parent 8e926f6 commit a96e1f8

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: e9046381228bb1a0998b2d04a0014a68a9cee35d
32+
refs/heads/beta: 9febb895a8bbefb8ed673b3553f79e1499fc0ca4
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: a224db5e630715d9f46938fe07b58eb644e3c27d

branches/beta/src/libcore/num/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,22 @@ macro_rules! int_impl {
563563
acc
564564
}
565565

566-
/// Computes the absolute value of `self`. `Int::min_value()` will be
567-
/// returned if the number is `Int::min_value()`.
566+
/// Computes the absolute value of `self`.
567+
///
568+
/// # Overflow behavior
569+
///
570+
/// The absolute value of `i32::min_value()` cannot be represented as an
571+
/// `i32`, and attempting to calculate it will cause an overflow. This
572+
/// means that code in debug mode will trigger a panic on this case and
573+
/// optimized code will return `i32::min_value()` without a panic.
568574
#[stable(feature = "rust1", since = "1.0.0")]
569575
#[inline]
570576
pub fn abs(self) -> $T {
571577
if self.is_negative() {
572-
self.wrapping_neg()
578+
// Note that the #[inline] above means that the overflow
579+
// semantics of this negation depend on the crate we're being
580+
// inlined into.
581+
-self
573582
} else {
574583
self
575584
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z force-overflow-checks=on
12+
13+
use std::thread;
14+
15+
fn main() {
16+
assert!(thread::spawn(|| i8::min_value().abs()).join().is_err());
17+
assert!(thread::spawn(|| i16::min_value().abs()).join().is_err());
18+
assert!(thread::spawn(|| i32::min_value().abs()).join().is_err());
19+
assert!(thread::spawn(|| i64::min_value().abs()).join().is_err());
20+
assert!(thread::spawn(|| isize::min_value().abs()).join().is_err());
21+
}

0 commit comments

Comments
 (0)