rust-lang / rust-lang/rust

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

Open
#153,667 4 comments 0 reactions 1 assignee View on GitHub

@vishnupoddar12 is already working on this.

Since Mar 10, 2026.

A-diagnostics D-papercut P-low T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

serror[E0599]: no method named `iter` found for opaque type `impl std::iter::Iterator<Item = &AssocItem> + '_` in the current scope
    --> compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:3130:67
     |
3130 |                 if !self.tcx.provided_trait_methods(trait_def_id).iter().any(|method| {
     |                                                                   ^^^^
     |
help: there is a method `filter` with a similar name, but with different arguments
    --> /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/iter/traits/iterator.rs:911:4

This can likely be done generally by looking at every method with that name and seeing if their return type matches the impl Trait we already have.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.