@@ -1142,17 +1142,19 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($Self
11421142$EndFeature, "
11431143```" ) ,
11441144 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1145+ #[ rustc_const_unstable( feature = "const_int_saturating" , issue = "53718" ) ]
11451146 #[ must_use = "this returns the result of the operation, \
11461147 without modifying the original"]
11471148 #[ 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 ) {
11511153 Self :: max_value( )
11521154 } else {
11531155 Self :: min_value( )
11541156 }
1155- } )
1157+ }
11561158 }
11571159 }
11581160
@@ -3195,11 +3197,15 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se
31953197"::MAX);" , $EndFeature, "
31963198```" ) ,
31973199 #[ stable( feature = "wrapping" , since = "1.7.0" ) ]
3200+ #[ rustc_const_unstable( feature = "const_int_saturating" , issue = "53718" ) ]
31983201 #[ must_use = "this returns the result of the operation, \
31993202 without modifying the original"]
32003203 #[ 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+ }
32033209 }
32043210 }
32053211
0 commit comments