Skip to content

manual_div_ceil suggests change that could alter behaviour #14333

@ojeda

Description

@ojeda

Description

For instance:

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

is not equivalent to:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions