@@ -1001,10 +1001,11 @@ $EndFeature, "
1001
1001
```" ) ,
1002
1002
1003
1003
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
1004
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
1004
1005
#[ must_use = "this returns the result of the operation, \
1005
1006
without modifying the original"]
1006
1007
#[ inline]
1007
- pub fn checked_pow( self , mut exp: u32 ) -> Option <Self > {
1008
+ pub const fn checked_pow( self , mut exp: u32 ) -> Option <Self > {
1008
1009
let mut base = self ;
1009
1010
let mut acc: Self = 1 ;
1010
1011
@@ -1188,10 +1189,11 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT
1188
1189
$EndFeature, "
1189
1190
```" ) ,
1190
1191
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
1192
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
1191
1193
#[ must_use = "this returns the result of the operation, \
1192
1194
without modifying the original"]
1193
1195
#[ inline]
1194
- pub fn saturating_pow( self , exp: u32 ) -> Self {
1196
+ pub const fn saturating_pow( self , exp: u32 ) -> Self {
1195
1197
match self . checked_pow( exp) {
1196
1198
Some ( x) => x,
1197
1199
None if self < 0 && exp % 2 == 1 => Self :: min_value( ) ,
@@ -1531,10 +1533,11 @@ assert_eq!(3i8.wrapping_pow(6), -39);",
1531
1533
$EndFeature, "
1532
1534
```" ) ,
1533
1535
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
1536
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
1534
1537
#[ must_use = "this returns the result of the operation, \
1535
1538
without modifying the original"]
1536
1539
#[ inline]
1537
- pub fn wrapping_pow( self , mut exp: u32 ) -> Self {
1540
+ pub const fn wrapping_pow( self , mut exp: u32 ) -> Self {
1538
1541
let mut base = self ;
1539
1542
let mut acc: Self = 1 ;
1540
1543
@@ -1908,10 +1911,11 @@ assert_eq!(3i8.overflowing_pow(5), (-13, true));",
1908
1911
$EndFeature, "
1909
1912
```" ) ,
1910
1913
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
1914
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
1911
1915
#[ must_use = "this returns the result of the operation, \
1912
1916
without modifying the original"]
1913
1917
#[ inline]
1914
- pub fn overflowing_pow( self , mut exp: u32 ) -> ( Self , bool ) {
1918
+ pub const fn overflowing_pow( self , mut exp: u32 ) -> ( Self , bool ) {
1915
1919
let mut base = self ;
1916
1920
let mut acc: Self = 1 ;
1917
1921
let mut overflown = false ;
@@ -1957,11 +1961,12 @@ assert_eq!(x.pow(5), 32);",
1957
1961
$EndFeature, "
1958
1962
```" ) ,
1959
1963
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1964
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
1960
1965
#[ must_use = "this returns the result of the operation, \
1961
1966
without modifying the original"]
1962
1967
#[ inline]
1963
1968
#[ rustc_inherit_overflow_checks]
1964
- pub fn pow( self , mut exp: u32 ) -> Self {
1969
+ pub const fn pow( self , mut exp: u32 ) -> Self {
1965
1970
let mut base = self ;
1966
1971
let mut acc = 1 ;
1967
1972
@@ -3127,10 +3132,11 @@ Basic usage:
3127
3132
assert_eq!(" , stringify!( $SelfT) , "::max_value().checked_pow(2), None);" , $EndFeature, "
3128
3133
```" ) ,
3129
3134
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
3135
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
3130
3136
#[ must_use = "this returns the result of the operation, \
3131
3137
without modifying the original"]
3132
3138
#[ inline]
3133
- pub fn checked_pow( self , mut exp: u32 ) -> Option <Self > {
3139
+ pub const fn checked_pow( self , mut exp: u32 ) -> Option <Self > {
3134
3140
let mut base = self ;
3135
3141
let mut acc: Self = 1 ;
3136
3142
@@ -3242,10 +3248,11 @@ assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT
3242
3248
$EndFeature, "
3243
3249
```" ) ,
3244
3250
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
3251
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
3245
3252
#[ must_use = "this returns the result of the operation, \
3246
3253
without modifying the original"]
3247
3254
#[ inline]
3248
- pub fn saturating_pow( self , exp: u32 ) -> Self {
3255
+ pub const fn saturating_pow( self , exp: u32 ) -> Self {
3249
3256
match self . checked_pow( exp) {
3250
3257
Some ( x) => x,
3251
3258
None => Self :: max_value( ) ,
@@ -3535,10 +3542,11 @@ Basic usage:
3535
3542
assert_eq!(3u8.wrapping_pow(6), 217);" , $EndFeature, "
3536
3543
```" ) ,
3537
3544
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
3545
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
3538
3546
#[ must_use = "this returns the result of the operation, \
3539
3547
without modifying the original"]
3540
3548
#[ inline]
3541
- pub fn wrapping_pow( self , mut exp: u32 ) -> Self {
3549
+ pub const fn wrapping_pow( self , mut exp: u32 ) -> Self {
3542
3550
let mut base = self ;
3543
3551
let mut acc: Self = 1 ;
3544
3552
@@ -3861,10 +3869,11 @@ Basic usage:
3861
3869
assert_eq!(3u8.overflowing_pow(6), (217, true));" , $EndFeature, "
3862
3870
```" ) ,
3863
3871
#[ stable( feature = "no_panic_pow" , since = "1.34.0" ) ]
3872
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
3864
3873
#[ must_use = "this returns the result of the operation, \
3865
3874
without modifying the original"]
3866
3875
#[ inline]
3867
- pub fn overflowing_pow( self , mut exp: u32 ) -> ( Self , bool ) {
3876
+ pub const fn overflowing_pow( self , mut exp: u32 ) -> ( Self , bool ) {
3868
3877
let mut base = self ;
3869
3878
let mut acc: Self = 1 ;
3870
3879
let mut overflown = false ;
@@ -3907,11 +3916,12 @@ Basic usage:
3907
3916
" , $Feature, "assert_eq!(2" , stringify!( $SelfT) , ".pow(5), 32);" , $EndFeature, "
3908
3917
```" ) ,
3909
3918
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3919
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
3910
3920
#[ must_use = "this returns the result of the operation, \
3911
3921
without modifying the original"]
3912
3922
#[ inline]
3913
3923
#[ rustc_inherit_overflow_checks]
3914
- pub fn pow( self , mut exp: u32 ) -> Self {
3924
+ pub const fn pow( self , mut exp: u32 ) -> Self {
3915
3925
let mut base = self ;
3916
3926
let mut acc = 1 ;
3917
3927
@@ -4022,7 +4032,8 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
4022
4032
// overflow cases it instead ends up returning the maximum value
4023
4033
// of the type, and can return 0 for 0.
4024
4034
#[ inline]
4025
- fn one_less_than_next_power_of_two( self ) -> Self {
4035
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
4036
+ const fn one_less_than_next_power_of_two( self ) -> Self {
4026
4037
if self <= 1 { return 0 ; }
4027
4038
4028
4039
let p = self - 1 ;
@@ -4050,9 +4061,10 @@ Basic usage:
4050
4061
assert_eq!(3" , stringify!( $SelfT) , ".next_power_of_two(), 4);" , $EndFeature, "
4051
4062
```" ) ,
4052
4063
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4064
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
4053
4065
#[ inline]
4054
4066
#[ rustc_inherit_overflow_checks]
4055
- pub fn next_power_of_two( self ) -> Self {
4067
+ pub const fn next_power_of_two( self ) -> Self {
4056
4068
self . one_less_than_next_power_of_two( ) + 1
4057
4069
}
4058
4070
}
@@ -4075,7 +4087,8 @@ $EndFeature, "
4075
4087
```" ) ,
4076
4088
#[ inline]
4077
4089
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4078
- pub fn checked_next_power_of_two( self ) -> Option <Self > {
4090
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
4091
+ pub const fn checked_next_power_of_two( self ) -> Option <Self > {
4079
4092
self . one_less_than_next_power_of_two( ) . checked_add( 1 )
4080
4093
}
4081
4094
}
@@ -4099,7 +4112,8 @@ $EndFeature, "
4099
4112
```" ) ,
4100
4113
#[ unstable( feature = "wrapping_next_power_of_two" , issue = "32463" ,
4101
4114
reason = "needs decision on wrapping behaviour" ) ]
4102
- pub fn wrapping_next_power_of_two( self ) -> Self {
4115
+ #[ rustc_const_unstable( feature = "const_int_pow" , issue = "53718" ) ]
4116
+ pub const fn wrapping_next_power_of_two( self ) -> Self {
4103
4117
self . one_less_than_next_power_of_two( ) . wrapping_add( 1 )
4104
4118
}
4105
4119
}
0 commit comments