rust-lang / rust-lang/rust-analyzer

Reference match in completion away the clippy

Open
#21,637 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When completing, it will auto dereference, just like:

pub fn bar(_: &str) { }
fn main() {
    let it = &"";
    bar($0); // complete `*it`
}

But clippy outputs:

warning: deref which would be done by auto-deref
 --> src/bin/main.rs:4:9
  |
4 |     bar(*it);
  |         ^^^ help: try: `it`

But if add condition !completion_without_ref.is_reference(),
the following example will report an error:

pub fn foo<'a>(s: &'a [&'a str]) -> impl Iterator<Item = &'a str> {
    s.iter().map(|it| {
        std::convert::identity(it) // instead of `*it`
    })
}

Compile error:

error[E0271]: expected `{closure@main.rs:2:18}` to return `&str`, but it returns `&&str`
 --> src/bin/main.rs:3:9
  |
1 |   pub fn foo<'a>(s: &'a [&'a str]) -> impl Iterator<Item = &'a str> {
  |                                       ----------------------------- closure used here
2 |       s.iter().map(|it| {
  |       -            ---- this closure
  |  _____|
  | |
3 | |         std::convert::identity(it) // instead of `*it`
  | |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `&&str`
4 | |     })

Is it worth improving on this? How to improve?

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

No project file or test is named; start by reproducing the two Rust completion examples and compare the generated completion with clippy's auto-deref warning and the iterator type error. Done means the intended reference match is handled without reintroducing the failing iterator case, with regression coverage for both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.