Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions library/core/src/num/imp/overflow_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ pub(in crate::num) const fn mul() -> ! {
panic!("attempt to multiply with overflow")
}

#[cold]
#[track_caller]
pub(in crate::num) const fn div() -> ! {
panic!("attempt to divide with overflow")
}

#[cold]
#[track_caller]
pub(in crate::num) const fn rem() -> ! {
Expand Down
18 changes: 12 additions & 6 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,12 @@ macro_rules! int_impl {
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
///
/// The only case where such an overflow can occur is when one divides `MIN / -1` on a signed type (where
/// [`MIN`](Self::MIN) is the negative minimal value for the type); this is equivalent to `-MIN`, a positive value
/// [`MIN`](Self::MIN) is the negative minimal value for the type); the result of this is `-MIN`, a positive value
/// that is too large to represent in the type.
///
/// Note that this is equivalent to normal division: `MIN / -1` will also panic both in
/// debug and release builds.
///
/// # Examples
///
/// ```
Expand All @@ -1010,8 +1013,8 @@ macro_rules! int_impl {
#[inline]
#[track_caller]
pub const fn strict_div(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_div(rhs);
if b { imp::overflow_panic::div() } else { a }
// Normal division already checks for "div-by-minus-1".
self / rhs
}

/// Checked Euclidean division. Computes `self.div_euclid(rhs)`,
Expand Down Expand Up @@ -1050,9 +1053,12 @@ macro_rules! int_impl {
/// This function will always panic on overflow, regardless of whether overflow checks are enabled.
///
/// The only case where such an overflow can occur is when one divides `MIN / -1` on a signed type (where
/// [`MIN`](Self::MIN) is the negative minimal value for the type); this is equivalent to `-MIN`, a positive value
/// [`MIN`](Self::MIN) is the negative minimal value for the type); the result of this is `-MIN`, a positive value
/// that is too large to represent in the type.
///
/// Note that this is equivalent to `div_euclid`: `MIN.div_euclid(-1)` will also panic both
/// in debug and release builds.
///
/// # Examples
///
/// ```
Expand All @@ -1077,8 +1083,8 @@ macro_rules! int_impl {
#[inline]
#[track_caller]
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_div_euclid(rhs);
if b { imp::overflow_panic::div() } else { a }
// Normal `div_euclid` already checks for "div-by-minus-1".
self.div_euclid(rhs)
}

/// Checked integer division without remainder. Computes `self / rhs`,
Expand Down
Loading