@@ -177,7 +177,7 @@ macro_rules! checked_op {
177177
178178// `Int` + `SignedInt` implemented for signed integers
179179macro_rules! int_impl {
180- ( $ActualT: ident, $UnsignedT: ty, $BITS: expr,
180+ ( $SelfT : ty , $ ActualT: ident, $UnsignedT: ty, $BITS: expr,
181181 $add_with_overflow: path,
182182 $sub_with_overflow: path,
183183 $mul_with_overflow: path) => {
@@ -850,6 +850,16 @@ macro_rules! int_impl {
850850 /// ```
851851 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
852852 #[ inline( always) ]
853+ #[ cfg( not( stage0) ) ]
854+ pub fn wrapping_shl( self , rhs: u32 ) -> Self {
855+ unsafe {
856+ intrinsics:: unchecked_shl( self , ( rhs & ( $BITS - 1 ) ) as $SelfT)
857+ }
858+ }
859+
860+ /// Stage 0
861+ #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
862+ #[ cfg( stage0) ]
853863 pub fn wrapping_shl( self , rhs: u32 ) -> Self {
854864 self . overflowing_shl( rhs) . 0
855865 }
@@ -875,6 +885,16 @@ macro_rules! int_impl {
875885 /// ```
876886 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
877887 #[ inline( always) ]
888+ #[ cfg( not( stage0) ) ]
889+ pub fn wrapping_shr( self , rhs: u32 ) -> Self {
890+ unsafe {
891+ intrinsics:: unchecked_shr( self , ( rhs & ( $BITS - 1 ) ) as $SelfT)
892+ }
893+ }
894+
895+ /// Stage 0
896+ #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
897+ #[ cfg( stage0) ]
878898 pub fn wrapping_shr( self , rhs: u32 ) -> Self {
879899 self . overflowing_shr( rhs) . 0
880900 }
@@ -1089,6 +1109,15 @@ macro_rules! int_impl {
10891109 /// ```
10901110 #[ inline]
10911111 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1112+ #[ cfg( not( stage0) ) ]
1113+ pub fn overflowing_shl( self , rhs: u32 ) -> ( Self , bool ) {
1114+ ( self . wrapping_shl( rhs) , ( rhs > ( $BITS - 1 ) ) )
1115+ }
1116+
1117+ /// Stage 0
1118+ #[ inline]
1119+ #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1120+ #[ cfg( stage0) ]
10921121 pub fn overflowing_shl( self , rhs: u32 ) -> ( Self , bool ) {
10931122 ( self << ( rhs & ( $BITS - 1 ) ) , ( rhs > ( $BITS - 1 ) ) )
10941123 }
@@ -1111,6 +1140,15 @@ macro_rules! int_impl {
11111140 /// ```
11121141 #[ inline]
11131142 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1143+ #[ cfg( not( stage0) ) ]
1144+ pub fn overflowing_shr( self , rhs: u32 ) -> ( Self , bool ) {
1145+ ( self . wrapping_shr( rhs) , ( rhs > ( $BITS - 1 ) ) )
1146+ }
1147+
1148+ /// Stage 0
1149+ #[ inline]
1150+ #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1151+ #[ cfg( stage0) ]
11141152 pub fn overflowing_shr( self , rhs: u32 ) -> ( Self , bool ) {
11151153 ( self >> ( rhs & ( $BITS - 1 ) ) , ( rhs > ( $BITS - 1 ) ) )
11161154 }
@@ -1268,39 +1306,39 @@ macro_rules! int_impl {
12681306
12691307#[ lang = "i8" ]
12701308impl i8 {
1271- int_impl ! { i8 , u8 , 8 ,
1309+ int_impl ! { i8 , i8 , u8 , 8 ,
12721310 intrinsics:: add_with_overflow,
12731311 intrinsics:: sub_with_overflow,
12741312 intrinsics:: mul_with_overflow }
12751313}
12761314
12771315#[ lang = "i16" ]
12781316impl i16 {
1279- int_impl ! { i16 , u16 , 16 ,
1317+ int_impl ! { i16 , i16 , u16 , 16 ,
12801318 intrinsics:: add_with_overflow,
12811319 intrinsics:: sub_with_overflow,
12821320 intrinsics:: mul_with_overflow }
12831321}
12841322
12851323#[ lang = "i32" ]
12861324impl i32 {
1287- int_impl ! { i32 , u32 , 32 ,
1325+ int_impl ! { i32 , i32 , u32 , 32 ,
12881326 intrinsics:: add_with_overflow,
12891327 intrinsics:: sub_with_overflow,
12901328 intrinsics:: mul_with_overflow }
12911329}
12921330
12931331#[ lang = "i64" ]
12941332impl i64 {
1295- int_impl ! { i64 , u64 , 64 ,
1333+ int_impl ! { i64 , i64 , u64 , 64 ,
12961334 intrinsics:: add_with_overflow,
12971335 intrinsics:: sub_with_overflow,
12981336 intrinsics:: mul_with_overflow }
12991337}
13001338
13011339#[ lang = "i128" ]
13021340impl i128 {
1303- int_impl ! { i128 , u128 , 128 ,
1341+ int_impl ! { i128 , i128 , u128 , 128 ,
13041342 intrinsics:: add_with_overflow,
13051343 intrinsics:: sub_with_overflow,
13061344 intrinsics:: mul_with_overflow }
@@ -1309,7 +1347,7 @@ impl i128 {
13091347#[ cfg( target_pointer_width = "16" ) ]
13101348#[ lang = "isize" ]
13111349impl isize {
1312- int_impl ! { i16 , u16 , 16 ,
1350+ int_impl ! { isize , i16 , u16 , 16 ,
13131351 intrinsics:: add_with_overflow,
13141352 intrinsics:: sub_with_overflow,
13151353 intrinsics:: mul_with_overflow }
@@ -1318,7 +1356,7 @@ impl isize {
13181356#[ cfg( target_pointer_width = "32" ) ]
13191357#[ lang = "isize" ]
13201358impl isize {
1321- int_impl ! { i32 , u32 , 32 ,
1359+ int_impl ! { isize , i32 , u32 , 32 ,
13221360 intrinsics:: add_with_overflow,
13231361 intrinsics:: sub_with_overflow,
13241362 intrinsics:: mul_with_overflow }
@@ -1327,15 +1365,15 @@ impl isize {
13271365#[ cfg( target_pointer_width = "64" ) ]
13281366#[ lang = "isize" ]
13291367impl isize {
1330- int_impl ! { i64 , u64 , 64 ,
1368+ int_impl ! { isize , i64 , u64 , 64 ,
13311369 intrinsics:: add_with_overflow,
13321370 intrinsics:: sub_with_overflow,
13331371 intrinsics:: mul_with_overflow }
13341372}
13351373
13361374// `Int` + `UnsignedInt` implemented for unsigned integers
13371375macro_rules! uint_impl {
1338- ( $ActualT: ty, $BITS: expr,
1376+ ( $SelfT : ty , $ ActualT: ty, $BITS: expr,
13391377 $ctpop: path,
13401378 $ctlz: path,
13411379 $cttz: path,
@@ -1978,6 +2016,16 @@ macro_rules! uint_impl {
19782016 /// ```
19792017 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
19802018 #[ inline( always) ]
2019+ #[ cfg( not( stage0) ) ]
2020+ pub fn wrapping_shl( self , rhs: u32 ) -> Self {
2021+ unsafe {
2022+ intrinsics:: unchecked_shl( self , ( rhs & ( $BITS - 1 ) ) as $SelfT)
2023+ }
2024+ }
2025+
2026+ /// Stage 0
2027+ #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
2028+ #[ cfg( stage0) ]
19812029 pub fn wrapping_shl( self , rhs: u32 ) -> Self {
19822030 self . overflowing_shl( rhs) . 0
19832031 }
@@ -2003,6 +2051,16 @@ macro_rules! uint_impl {
20032051 /// ```
20042052 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
20052053 #[ inline( always) ]
2054+ #[ cfg( not( stage0) ) ]
2055+ pub fn wrapping_shr( self , rhs: u32 ) -> Self {
2056+ unsafe {
2057+ intrinsics:: unchecked_shr( self , ( rhs & ( $BITS - 1 ) ) as $SelfT)
2058+ }
2059+ }
2060+
2061+ /// Stage 0
2062+ #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
2063+ #[ cfg( stage0) ]
20062064 pub fn wrapping_shr( self , rhs: u32 ) -> Self {
20072065 self . overflowing_shr( rhs) . 0
20082066 }
@@ -2170,6 +2228,15 @@ macro_rules! uint_impl {
21702228 /// ```
21712229 #[ inline]
21722230 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2231+ #[ cfg( not( stage0) ) ]
2232+ pub fn overflowing_shl( self , rhs: u32 ) -> ( Self , bool ) {
2233+ ( self . wrapping_shl( rhs) , ( rhs > ( $BITS - 1 ) ) )
2234+ }
2235+
2236+ /// Stage 0
2237+ #[ inline]
2238+ #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2239+ #[ cfg( stage0) ]
21732240 pub fn overflowing_shl( self , rhs: u32 ) -> ( Self , bool ) {
21742241 ( self << ( rhs & ( $BITS - 1 ) ) , ( rhs > ( $BITS - 1 ) ) )
21752242 }
@@ -2192,6 +2259,16 @@ macro_rules! uint_impl {
21922259 /// ```
21932260 #[ inline]
21942261 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2262+ #[ cfg( not( stage0) ) ]
2263+ pub fn overflowing_shr( self , rhs: u32 ) -> ( Self , bool ) {
2264+ ( self . wrapping_shr( rhs) , ( rhs > ( $BITS - 1 ) ) )
2265+
2266+ }
2267+
2268+ /// Stage 0
2269+ #[ inline]
2270+ #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2271+ #[ cfg( stage0) ]
21952272 pub fn overflowing_shr( self , rhs: u32 ) -> ( Self , bool ) {
21962273 ( self >> ( rhs & ( $BITS - 1 ) ) , ( rhs > ( $BITS - 1 ) ) )
21972274 }
@@ -2292,7 +2369,7 @@ macro_rules! uint_impl {
22922369
22932370#[ lang = "u8" ]
22942371impl u8 {
2295- uint_impl ! { u8 , 8 ,
2372+ uint_impl ! { u8 , u8 , 8 ,
22962373 intrinsics:: ctpop,
22972374 intrinsics:: ctlz,
22982375 intrinsics:: cttz,
@@ -2304,7 +2381,7 @@ impl u8 {
23042381
23052382#[ lang = "u16" ]
23062383impl u16 {
2307- uint_impl ! { u16 , 16 ,
2384+ uint_impl ! { u16 , u16 , 16 ,
23082385 intrinsics:: ctpop,
23092386 intrinsics:: ctlz,
23102387 intrinsics:: cttz,
@@ -2316,7 +2393,7 @@ impl u16 {
23162393
23172394#[ lang = "u32" ]
23182395impl u32 {
2319- uint_impl ! { u32 , 32 ,
2396+ uint_impl ! { u32 , u32 , 32 ,
23202397 intrinsics:: ctpop,
23212398 intrinsics:: ctlz,
23222399 intrinsics:: cttz,
@@ -2328,7 +2405,7 @@ impl u32 {
23282405
23292406#[ lang = "u64" ]
23302407impl u64 {
2331- uint_impl ! { u64 , 64 ,
2408+ uint_impl ! { u64 , u64 , 64 ,
23322409 intrinsics:: ctpop,
23332410 intrinsics:: ctlz,
23342411 intrinsics:: cttz,
@@ -2340,7 +2417,7 @@ impl u64 {
23402417
23412418#[ lang = "u128" ]
23422419impl u128 {
2343- uint_impl ! { u128 , 128 ,
2420+ uint_impl ! { u128 , u128 , 128 ,
23442421 intrinsics:: ctpop,
23452422 intrinsics:: ctlz,
23462423 intrinsics:: cttz,
@@ -2353,7 +2430,7 @@ impl u128 {
23532430#[ cfg( target_pointer_width = "16" ) ]
23542431#[ lang = "usize" ]
23552432impl usize {
2356- uint_impl ! { u16 , 16 ,
2433+ uint_impl ! { usize , u16 , 16 ,
23572434 intrinsics:: ctpop,
23582435 intrinsics:: ctlz,
23592436 intrinsics:: cttz,
@@ -2365,7 +2442,7 @@ impl usize {
23652442#[ cfg( target_pointer_width = "32" ) ]
23662443#[ lang = "usize" ]
23672444impl usize {
2368- uint_impl ! { u32 , 32 ,
2445+ uint_impl ! { usize , u32 , 32 ,
23692446 intrinsics:: ctpop,
23702447 intrinsics:: ctlz,
23712448 intrinsics:: cttz,
@@ -2378,7 +2455,7 @@ impl usize {
23782455#[ cfg( target_pointer_width = "64" ) ]
23792456#[ lang = "usize" ]
23802457impl usize {
2381- uint_impl ! { u64 , 64 ,
2458+ uint_impl ! { usize , u64 , 64 ,
23822459 intrinsics:: ctpop,
23832460 intrinsics:: ctlz,
23842461 intrinsics:: cttz,
0 commit comments