RS.CLIPPY.MANUAL_DIV_CEIL

Manually reimplementing `div_ceil`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_div_ceil. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for an expression like (x + (y - 1)) / y which is a common manual reimplementation of x.div_ceil(y).

Why is this bad?

It's simpler, clearer and more readable.

Example

let x: i32 = 7;
let y: i32 = 4;
let div = (x + (y - 1)) / y;

Use instead:

#![feature(int_roundings)]
let x: i32 = 7;
let y: i32 = 4;
let div = x.div_ceil(y);

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)