External Publication
Visit Post

Why is strict_div implemented in terms of overflowing_div for signed integers?

Rust Internals [Unofficial] June 9, 2026
Source

I was unable to find a satisfying answer to this question, so I thought I'd ask here. strict_div is currently implemented as follows for signed integers:

pub const fn strict_div(self, rhs: Self) -> Self {
    let (a, b) = self.overflowing_div(rhs);
    if b { imp::overflow_panic::div() } else { a }
}

However, div already panics on overflow even in release mode, meaning that strict_div should be exactly equivalent to div. This made me wonder why signed integers don't use the same implementation strategy as unsigned integers:

pub const fn strict_div(self, rhs: Self) -> Self {
    self / rhs
}

Can anyone offer any insights?

Discussion in the ATmosphere

Loading comments...