rust-lang / rust-lang/rust-clippy
useless op on lhs of integer division or modulo
@Twil3akine is already working on this.
Since May 10, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
(x + n + y) % n or (x + n + y) / n can simply be replaced by (x + y) % n or (x + y) / n + 1
this isn't true for the following computations on unsigned integers:
(x + n - y) % n or (x + n - y) / n
as they might go negative due to the subtraction. For explicitly evading INT_MAX issues, this lint will cause false positives, but that could be evaded by not linting if INT_MAX is mentioned somewhere near the operation.
most likely, whenever this lint triggers, it is a bug in the equation, so the suggestion doesn't fix the underlying issue, but it will raise awareness of it.
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.