rust-lang / rust-lang/rust-analyzer

autoIter: offer into_iter()-prefixed completions when iter() is also available

Open
#23,157 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer.completion.autoIter.enable can provide iterator method completions by prefixing them with iter() or into_iter().

However, when both are available, only the iter() path appears to be offered.

For example:

fn main() {
    let v = vec![1, 2, 3];

    v.ma
    // completion: iter().map(...)
    // no completion: into_iter().map(...)
}

It would be useful to offer both:

v.iter().map(...)
v.into_iter().map(...)

These are not equivalent completions. For example, for Vec<T>, iter() produces items of type &T, while into_iter() consumes the vector and produces items of type T.

The current implementation seems to intentionally prefer iter() and only try into_iter() as a fallback:

if let Some((iter, iter_sym)) = iter.or_else(into_iter) {
    // ...
}

So when iter() is available, the into_iter() path is not considered.

Would it make sense for autoIter to offer both paths when they result in meaningfully different iterator types?

If showing both unconditionally would add too much completion noise, another possibility would be to offer both only when the resulting iterator/item types differ.

Related:

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.

Research direction

Start in crates/ide-completion/src/completions/dot.rs and inspect the autoIter logic that uses iter() with into_iter() as a fallback. Read the linked implementation PR and related issue for existing completion behavior, then verify the Vec example and define tests showing when both completion paths should appear. Done means the distinct iter() and into_iter() chains are offered without unnecessary duplicate completion noise.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.