File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
29
29
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
30
30
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
31
31
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32
- refs/heads/beta: e9046381228bb1a0998b2d04a0014a68a9cee35d
32
+ refs/heads/beta: 9febb895a8bbefb8ed673b3553f79e1499fc0ca4
33
33
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
34
34
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35
35
refs/heads/tmp: a224db5e630715d9f46938fe07b58eb644e3c27d
Original file line number Diff line number Diff line change @@ -563,13 +563,22 @@ macro_rules! int_impl {
563
563
acc
564
564
}
565
565
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.
568
574
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
569
575
#[ inline]
570
576
pub fn abs( self ) -> $T {
571
577
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
573
582
} else {
574
583
self
575
584
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments