Skip to content

explicit_auto_deref could suggest variale with borrows #9109

@matthiaskrgr

Description

@matthiaskrgr

Description

The op_ref lint already does this:

warning: needlessly taken reference of left operand
   --> crates/rust-analyzer/src/reload.rs:582:51
    |
582 |             if dummy_replace.iter().any(|replace| &**replace == name) {
    |                                                   ----------^^^^^^^^
    |                                                   |
    |                                                   help: use the left value directly: `**replace`
    |
    = note: `#[warn(clippy::op_ref)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref

IMO its easier to understand if the span and the suggestion includes the borrows

so

warning: deref which would be done by auto-deref
   --> crates/rust-analyzer/src/handlers.rs:981:41
    |
981 |         snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?;
    |                                         ^^^^^^^^^^^^^^^^ help: try this: `params.new_name`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

could become

warning: deref which would be done by auto-deref
   --> crates/rust-analyzer/src/handlers.rs:981:41
    |
981 |         snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?;
    |                                        ^^^^^^^^^^^^^^^^^ help: try this: `&params.new_name`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Version

clippy 0.1.64 (f2d9393 2022-07-02)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions