rust-lang / rust-lang/rust-clippy
catch manual next_multiple_of
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.