@@ -926,21 +926,34 @@ macro_rules! int_impl {
926926 /// Basic usage:
927927 ///
928928 /// ```
929+ /// #![feature(saturating_div)]
930+ ///
931+ #[ doc = concat!( "assert_eq!(5" , stringify!( $SelfT) , ".saturating_div(2), 2);" ) ]
932+ #[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MAX.saturating_div(-1), " , stringify!( $SelfT) , "::MIN + 1);" ) ]
933+ #[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MIN.saturating_div(-1), " , stringify!( $SelfT) , "::MAX);" ) ]
929934 ///
930935 /// ```
931- #[ unstable( feature = "saturating_int_impl" , issue = "87920" ) ]
932- #[ rustc_const_unstable( feature = "saturating_int_impl" , issue = "87920" ) ]
936+ ///
937+ /// ```should_panic
938+ /// #![feature(saturating_div)]
939+ ///
940+ #[ doc = concat!( "let _ = 1" , stringify!( $SelfT) , ".saturating_div(0);" ) ]
941+ ///
942+ /// ```
943+ #[ unstable( feature = "saturating_div" , issue = "87920" ) ]
944+ #[ rustc_const_unstable( feature = "saturating_div" , issue = "87920" ) ]
933945 #[ must_use = "this returns the result of the operation, \
934946 without modifying the original"]
935947 #[ inline]
936948 pub const fn saturating_div( self , rhs: Self ) -> Self {
937- match self . checked_div( rhs) {
938- Some ( x) => x,
939- None => if ( self < 0 ) == ( rhs < 0 ) {
940- Self :: MAX
941- } else {
942- Self :: MIN
943- }
949+ let ( result, overflowed) = self . overflowing_div( rhs) ;
950+
951+ if !overflowed {
952+ result
953+ } else if ( self < 0 ) == ( rhs < 0 ) {
954+ Self :: MAX
955+ } else {
956+ Self :: MIN
944957 }
945958 }
946959
0 commit comments