@@ -1175,7 +1175,7 @@ $EndFeature, "
1175
1175
```" ) ,
1176
1176
#[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
1177
1177
#[ inline]
1178
- pub fn wrapping_neg( self ) -> Self {
1178
+ pub const fn wrapping_neg( self ) -> Self {
1179
1179
self . overflowing_neg( ) . 0
1180
1180
}
1181
1181
}
@@ -1529,12 +1529,8 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self
1529
1529
```" ) ,
1530
1530
#[ inline]
1531
1531
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1532
- pub fn overflowing_neg( self ) -> ( Self , bool ) {
1533
- if self == Self :: min_value( ) {
1534
- ( Self :: min_value( ) , true )
1535
- } else {
1536
- ( -self , false )
1537
- }
1532
+ pub const fn overflowing_neg( self ) -> ( Self , bool ) {
1533
+ ( ( self ^ -1 ) . wrapping_add( 1 ) , s == $SelfT:: min_value( ) )
1538
1534
}
1539
1535
}
1540
1536
@@ -3017,7 +3013,7 @@ assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);
3017
3013
/// ```
3018
3014
#[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
3019
3015
#[ inline]
3020
- pub fn wrapping_neg( self ) -> Self {
3016
+ pub const fn wrapping_neg( self ) -> Self {
3021
3017
self . overflowing_neg( ) . 0
3022
3018
}
3023
3019
@@ -3322,7 +3318,7 @@ assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2i32 as ", stringify!(
3322
3318
```" ) ,
3323
3319
#[ inline]
3324
3320
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
3325
- pub fn overflowing_neg( self ) -> ( Self , bool ) {
3321
+ pub const fn overflowing_neg( self ) -> ( Self , bool ) {
3326
3322
( ( !self ) . wrapping_add( 1 ) , self != 0 )
3327
3323
}
3328
3324
}
0 commit comments