Skip to content

explicit_auto_deref gives wrong suggestion when using Arc #9310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Swatinem opened this issue Aug 9, 2022 · 2 comments
Closed

explicit_auto_deref gives wrong suggestion when using Arc #9310

Swatinem opened this issue Aug 9, 2022 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Swatinem
Copy link
Contributor

Swatinem commented Aug 9, 2022

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

@Swatinem Swatinem added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 9, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Aug 9, 2022

The suggestion is to replace *arc with arc, leaving the code as &arc. The suggestion was changed to be clearer in #9126.

@Swatinem
Copy link
Contributor Author

Swatinem commented Aug 9, 2022

replace *arc with arc, leaving the code as &arc

Wow, that indeed was very hard to spot.

@Swatinem Swatinem closed this as completed Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants