rust-lang / rust-lang/rust-clippy

catch manual next_multiple_of

Open
#16,728 2 comments 0 reactions 1 assignee View on GitHub

@qdot3 is already working on this.

Since Aug 3, 2026.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

detect manual implementation of the next_multiple_of, e.g. a.div_ceil(b) * b. Note that this may combine clippy::manual_div_ceil detection as well, e.g. (x + (y - 1)) / y * y.

Make sure to include checked_next_multiple_of variant detection

Advantage
  • shows clear intent rather
  • reduces code complexity
  • prevents accidental bugs
Drawbacks

No response

Example
use std::ops::Mul;

fn mult1(a: u32, b: u32) -> u32 {
    a.div_ceil(b) * b
}

fn mult2(a: u32, b: u32) -> u32 {
    a.div_ceil(b).mul(b)
}

fn mult3(a: u32, b: u32) -> u32 {
    (a + (b - 1)) / b * b
}

Could be written as:

a.next_multiple_of(b)
Comparison with existing lints

manual_div_ceil does something similar

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.