@@ -1019,25 +1019,29 @@ macro_rules! int_impl {
10191019 }
10201020 }
10211021
1022- /// Checked integer division without remainder. Computes `self / rhs`.
1022+ /// Integer division without remainder. Computes `self / rhs`, returning `None` if `self % rhs != 0 `.
10231023 ///
10241024 /// # Panics
10251025 ///
1026- /// This function will panic if `rhs == 0`, the division results in overflow,
1027- /// or `self % rhs != 0`.
1026+ /// This function will panic if `rhs == 0`.
1027+ ///
1028+ /// ## Overflow behavior
1029+ ///
1030+ /// On overflow, this function will panic if overflow checks are enabled (default in debug
1031+ /// mode) and wrap if overflow checks are disabled (default in release mode).
10281032 ///
10291033 /// # Examples
10301034 ///
10311035 /// ```
10321036 /// #![feature(exact_div)]
1033- #[ doc = concat!( "assert_eq!(64" , stringify!( $SelfT) , ".exact_div(2), 32);" ) ]
1034- #[ doc = concat!( "assert_eq!(64" , stringify!( $SelfT) , ".exact_div(32), 2);" ) ]
1035- #[ doc = concat!( "assert_eq!((" , stringify!( $SelfT) , "::MIN + 1).exact_div(-1), " , stringify!( $Max) , ");" ) ]
1037+ #[ doc = concat!( "assert_eq!(64" , stringify!( $SelfT) , ".exact_div(2), Some(32));" ) ]
1038+ #[ doc = concat!( "assert_eq!(64" , stringify!( $SelfT) , ".exact_div(32), Some(2));" ) ]
1039+ #[ doc = concat!( "assert_eq!((" , stringify!( $SelfT) , "::MIN + 1).exact_div(-1), Some(" , stringify!( $Max) , "));" ) ]
1040+ #[ doc = concat!( "assert_eq!(65" , stringify!( $SelfT) , ".exact_div(2), None);" ) ]
10361041 /// ```
1037- ///
10381042 /// ```should_panic
10391043 /// #![feature(exact_div)]
1040- #[ doc = concat!( "let _ = 65 " , stringify!( $SelfT) , ".exact_div(2 );" ) ]
1044+ #[ doc = concat!( "let _ = 64 " , stringify!( $SelfT) , ".exact_div(0 );" ) ]
10411045 /// ```
10421046 /// ```should_panic
10431047 /// #![feature(exact_div)]
@@ -1050,10 +1054,12 @@ macro_rules! int_impl {
10501054 #[ must_use = "this returns the result of the operation, \
10511055 without modifying the original"]
10521056 #[ inline]
1053- pub const fn exact_div( self , rhs: Self ) -> Self {
1054- match self . checked_exact_div( rhs) {
1055- Some ( x) => x,
1056- None => panic!( "Failed to divide without remainder" ) ,
1057+ #[ rustc_inherit_overflow_checks]
1058+ pub const fn exact_div( self , rhs: Self ) -> Option <Self > {
1059+ if self % rhs != 0 {
1060+ None
1061+ } else {
1062+ Some ( self / rhs)
10571063 }
10581064 }
10591065
0 commit comments