Skip to content

Do not lint when the two differing identifiers in a suspicious grouping#17177

Open
durationextender wants to merge 1 commit into
rust-lang:masterfrom
durationextender:fix/suspicious-op-groupings-fp-17143
Open

Do not lint when the two differing identifiers in a suspicious grouping#17177
durationextender wants to merge 1 commit into
rust-lang:masterfrom
durationextender:fix/suspicious-op-groupings-fp-17143

Conversation

@durationextender

@durationextender durationextender commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

When f(x) && g(y) && x != y is written, the presence of x != y
proves the programmer intentionally used different variables. The lint
was incorrectly suggesting f(x) && g(x) as a fix.

Before emitting the suggestion, we now scan the rest of the binary op
chain for any comparison operator (!=, ==, <, >, <=, >=)
that contains both of the differing identifiers. If found, the lint is
suppressed.

fixes #17143

changelog: [suspicious_operation_groupings]: do not lint when the differing identifiers are explicitly compared elsewhere in the same expression

probably a better way of handling this, but i couldnt figure out how to do it better performance/idiomatic and logic wise, sorry.

are explicitly compared with a relational operator elsewhere in the same
expression, as this proves the use of different variables was intentional this fixes 17143
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 6, 2026
@rustbot

rustbot commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
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: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@durationextender

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@Jarcho

Jarcho commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

I don't really want to have changes to this lint without having a good description of what it should and shouldn't catch. This includes both an abstract description that can be used to judge specific cases and a sizable set of specific cases.

For this PR you look to be really special casing the particular issue, but it's not clear f(x) && g(y) should be linting in any case. There's not really anything to go by in that expression to make such a judgment.

@mi2ebi

mi2ebi commented Jun 8, 2026

Copy link
Copy Markdown

it's not clear f(x) && g(y) should be linting in any case. There's not really anything to go by in that expression to make such a judgment.

this does make sense to me, maybe i should have considered that when writing the issue

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

Labels

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.

FP for suspicious_operation_groupings

4 participants