rust-lang / rust-lang/rust-clippy
`manual_div_ceil` does not trigger for alternate form
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The lint triggers for expressions of the form (a + b - 1) / b but not of the form (a - 1) / b + 1. For unsigned integers, these are equivalent ignoring overflow/underflow.
Lint Name
manual_div_ceil
Reproducer
I tried this code (playground):
fn div_ceil(a: u32, b: u32) -> u32 {
(a - 1) / b + 1
}
I expected to see this happen:
The manual_div_ceil lint should trigger, suggesting a.div_ceil(b).
Instead, this happened:
Nothing.
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.
Research direction
Start by locating the implementation and tests for the manual_div_ceil lint, then run Clippy on the provided (a - 1) / b + 1 reproducer. Confirm that the alternate unsigned-integer form is recognized and that the diagnostic suggests a.div_ceil(b), while preserving existing behavior for the original form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100