Skip to content

Add redundant_modulo_divisor lint - #16983

Open
Twil3akine wants to merge 2 commits into
rust-lang:masterfrom
Twil3akine:redundant-modulo-divisor
Open

Add redundant_modulo_divisor lint#16983
Twil3akine wants to merge 2 commits into
rust-lang:masterfrom
Twil3akine:redundant-modulo-divisor

Conversation

@Twil3akine

@Twil3akine Twil3akine commented May 10, 2026

Copy link
Copy Markdown
Contributor

Implements the % subset of #1324.

This adds redundant_modulo_divisor, which warns when the left-hand side of a remainder expression contains the divisor itself as an additive term.

Examples that lint:

(x + n + y) % n
(x + (n + y) + z) % (n + y)

This PR intentionally:

  • handles only %, not /
  • emits no suggestion
  • handles only primitive integer operands
  • requires at least three additive terms on the left-hand side
  • ignores subtraction cases such as (x + n - y) % n
  • does not search inside arbitrary additive subexpressions, to avoid false positives such as (x + (n + 1) + y) % n

Tested with:

cargo fmt --check
TESTNAME=redundant_modulo_divisor cargo uitest

changelog: [redundant_modulo_divisor]: add new lint for redundant additions of the modulo divisor

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 10, 2026
@rustbot

rustbot commented May 10, 2026

Copy link
Copy Markdown
Collaborator

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #17552) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants