@@ -1142,17 +1142,19 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($Self
1142
1142
$EndFeature, "
1143
1143
```" ) ,
1144
1144
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1145
+ #[ rustc_const_unstable( feature = "const_int_saturating" , issue = "53718" ) ]
1145
1146
#[ must_use = "this returns the result of the operation, \
1146
1147
without modifying the original"]
1147
1148
#[ inline]
1148
- pub fn saturating_mul( self , rhs: Self ) -> Self {
1149
- self . checked_mul( rhs) . unwrap_or_else( || {
1150
- if ( self < 0 ) == ( rhs < 0 ) {
1149
+ pub const fn saturating_mul( self , rhs: Self ) -> Self {
1150
+ match self . checked_mul( rhs) {
1151
+ Some ( x) => x,
1152
+ None => if ( self < 0 ) == ( rhs < 0 ) {
1151
1153
Self :: max_value( )
1152
1154
} else {
1153
1155
Self :: min_value( )
1154
1156
}
1155
- } )
1157
+ }
1156
1158
}
1157
1159
}
1158
1160
@@ -3195,11 +3197,15 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se
3195
3197
"::MAX);" , $EndFeature, "
3196
3198
```" ) ,
3197
3199
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
3200
+ #[ rustc_const_unstable( feature = "const_int_saturating" , issue = "53718" ) ]
3198
3201
#[ must_use = "this returns the result of the operation, \
3199
3202
without modifying the original"]
3200
3203
#[ inline]
3201
- pub fn saturating_mul( self , rhs: Self ) -> Self {
3202
- self . checked_mul( rhs) . unwrap_or( Self :: max_value( ) )
3204
+ pub const fn saturating_mul( self , rhs: Self ) -> Self {
3205
+ match self . checked_mul( rhs) {
3206
+ Some ( x) => x,
3207
+ None => Self :: max_value( ) ,
3208
+ }
3203
3209
}
3204
3210
}
3205
3211
0 commit comments