Skip to content

hir_typeck: suggest removing redundant .iter() and iter_mut ()calls#153700

Open
vishnupoddar12 wants to merge 1 commit intorust-lang:mainfrom
vishnupoddar12:issue-153667-fix
Open

hir_typeck: suggest removing redundant .iter() and iter_mut ()calls#153700
vishnupoddar12 wants to merge 1 commit intorust-lang:mainfrom
vishnupoddar12:issue-153667-fix

Conversation

@vishnupoddar12
Copy link
Contributor

@vishnupoddar12 vishnupoddar12 commented Mar 11, 2026

This diagnostic intercepts cases where .iter() or .iter_mut() is called on a type that already implements Iterator

Instead of confusing trait fallback suggestions, it explicitly guides the user to remove the .iter() call. It implements precise span computation to support cargo fix while carefully preserving all inline comments and horizontal whitespace during the AST string replacement.

Fixes #153667

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 11, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2026

r? @fmease

rustbot has assigned @fmease.
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: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@vishnupoddar12 vishnupoddar12 force-pushed the issue-153667-fix branch 4 times, most recently from 6b03e95 to 8f0debd Compare March 11, 2026 16:34
This diagnostic intercepts cases where `.iter()` is called on a type
that already implements `Iterator`

Instead of confusing trait fallback suggestions, it explicitly guides
the user to remove the `.iter()` call. It implements precise span
computation to support `cargo fix` while carefully preserving all inline
comments and horizontal whitespace during the AST string replacement.
@vishnupoddar12 vishnupoddar12 changed the title hir_typeck: suggest removing redundant .iter() calls hir_typeck: suggest removing redundant .iter() and iter_mut ()calls Mar 11, 2026
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When encountering .iter() on an impl Iterator, suggest removing the method call

3 participants