Skip to content

Reference match in completion away the clippy #21637

@A4-Tacks

Description

@A4-Tacks

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 `{[email protected]: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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions