Skip to content

explicit_auto_deref gives wrong suggestion when using Arc #9310

Closed
@Swatinem

Description

@Swatinem

Summary

I have some weird looking code which has a reborrow pattern for reasons I don’t understand but which seem to be wrong anyways: It uses &*arc to turn an Arc<T> into a &T, which is weird but the rustc compiler never seemed to mind.

Clippy now suggests to remove the &* entirely, which seems wrong.

Lint Name

explicit_auto_deref

Reproducer

I tried this code:

struct Foo;
let arc = std::sync::Arc::new(Foo);
fn f(_: &Foo) {}
f(&*arc);

I saw this happen:

warning: deref which would be done by auto-deref
  --> crates/symbolicator/src/main.rs:53:8
   |
53 |     f(&*arc);
   |        ^^^^ help: try this: `arc`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

I expected to see this happen:

It should suggest using just &arc, as I still need to borrow it to be able to deref.

Version

rustc 1.65.0-nightly (f03ce3096 2022-08-08)
binary: rustc
commit-hash: f03ce30962cf1b2a5158667eabae8bf6e8d1cb03
commit-date: 2022-08-08
host: x86_64-apple-darwin
release: 1.65.0-nightly
LLVM version: 14.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions