rust-lang / rust-lang/rust-clippy
`manual_is_multiple_of` should not trigger on literal divisors
Open
@mikhailofff is already working on this.
Since Feb 17, 2026.
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
The manual_is_multiple_of lint triggers on expressions like
if v % 2 == 0 { }
suggesting replacement with
if v.is_multiple_of(2) { }
Proposal: Skip this lint when the divisor is an integer literal.
Advantage
v % 2 == 0is an universal idiom across languages and understood immediatelyv.is_multiple_of(2)is longer to type and more complex to read- Main purpose of is_multiple_of() was probably avoiding panics due to division-by-zero; this does not apply to literal divisors (compile-time validation)
Drawbacks
No response
Example
Trigger on
let a = 2;
if v % a == 0 { } /// WARNING --> replace by v.is_multiple_of(a)
but not
if v % 2 == 0 { } /// NO warning
Comparison with existing lints
No response
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.