#14333·rust-clippy

`manual_div_ceil` suggests change that could alter behaviour

Author: ojedaCreated Mar 1, 2025Updated Sep 17, 2026
LabelsG-Rust-for-Linux

Description

For instance:

rust
fn f(x: u8) -> u8 {
    (x + 7) / 8
}

is not equivalent to:

rust
fn f(x: u8) -> u8 {
    x.div_ceil(8)
}

In particular, for inputs 249..=255: the former overflows (thus panics or returns 0), while the latter returns 32.

The user probably wants the latter, so the change may actually remove a bug. Nevertheless, should manual_div_ceil mention that overflowing inputs may change behavior? (ideally it would mention the range of those that overflow)

Version

rustc 1.86.0-beta.3 (42212a5c4 2025-02-27)

Additional Labels

No response