rust-lang / rust-lang/rust-clippy

`manual_is_multiple_of` should not trigger on literal divisors

Open
#16,537 1 comment 2 reactions 1 assignee View on GitHub

@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 == 0 is an universal idiom across languages and understood immediately
  • v.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

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.