Skip to content

Make unnecessary_fold commutative#16604

Merged
llogiq merged 1 commit intorust-lang:masterfrom
mikhailofff:fix/issue-16581
Feb 21, 2026
Merged

Make unnecessary_fold commutative#16604
llogiq merged 1 commit intorust-lang:masterfrom
mikhailofff:fix/issue-16581

Conversation

@mikhailofff
Copy link
Contributor

@mikhailofff mikhailofff commented Feb 21, 2026

To be honest, the changes are confusing.

First of all, it has already been stated that it would be wrong if we extended the lint to cover both sides.

// We only match against an accumulator on the left
// hand side. We could lint for .sum and .product when
// it's on the right, but don't for now (and this wouldn't
// be valid if we extended the lint to cover arbitrary numeric
// types).

Secondly, there is some monstrous expression in the get_triggered_expr_span function, and I think it could be rewritten more cleanly.

Anyway, even if it has to be implemented, I'm glad to rewrite it more thoroughly.

Fixes #16581.


changelog: [unnecessary_fold]: match against an accumulator on both sides.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 21, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 21, 2026

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, dswij, llogiq, samueltardieu

@llogiq
Copy link
Contributor

llogiq commented Feb 21, 2026

It would only be invalid if we supported arbitrary numeric types. So I don't see this as a problem. We can always revert if it becomes one.

The code itself looks ok to me. Thank you!

@llogiq llogiq added this pull request to the merge queue Feb 21, 2026
Merged via the queue into rust-lang:master with commit 9de20be Feb 21, 2026
16 of 17 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 21, 2026
@mikhailofff mikhailofff deleted the fix/issue-16581 branch February 21, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unnecessary_fold is not commutative

3 participants