Skip to content

Fix explicit_counter_loop FP when the counter is only modified inside the else block of let...else binding.#17023

Merged
Jarcho merged 1 commit into
rust-lang:masterfrom
relaxcn:explicit_counter_loop
Jun 8, 2026
Merged

Fix explicit_counter_loop FP when the counter is only modified inside the else block of let...else binding.#17023
Jarcho merged 1 commit into
rust-lang:masterfrom
relaxcn:explicit_counter_loop

Conversation

@relaxcn

@relaxcn relaxcn commented May 16, 2026

Copy link
Copy Markdown
Contributor

Fixes: #17014

changelog: [explicit_counter_loop]: Fix FP when the counter is only modified inside the else block of let...else binding.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 16, 2026
@rustbot

rustbot commented May 16, 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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

Comment thread clippy_lints/src/loops/utils.rs Outdated
Comment on lines +50 to +59
if let Some(els) = l.els {
if let Some(init) = l.init {
self.visit_expr(init);
}
self.depth += 1;
self.visit_block(els);
self.depth -= 1;
} else {
walk_local(self, l);
}

@Jarcho Jarcho May 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be:

if let Some(init) = l.init {
  self.visit_expr(init)
  if let Some(els) = l.els {
    self.depth += 1;
    self.visit_block(els);
    self.depth -= 1;
  }
}

Note that walk_local doesn't actually do anything other than waste time.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 21, 2026
@rustbot

rustbot commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@relaxcn relaxcn force-pushed the explicit_counter_loop branch from 028f495 to 22833b4 Compare May 24, 2026 14:20
@relaxcn

relaxcn commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 24, 2026

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho Jarcho added this pull request to the merge queue Jun 8, 2026
Merged via the queue into rust-lang:master with commit 53308b5 Jun 8, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 8, 2026
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.

Lint explicit_counter_loop incorrectly triggers when incrementing in let ... else ...

3 participants