rust-lang / rust-lang/rust-clippy
explicit_auto_deref suggests code that does not compile
Open
Nobody has claimed this yet.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Reproducer attached. Clippy suggests to remove the dereference operator but without it the code doesn't compile.
Lint Name
explicit_auto_deref
Reproducer
I tried this code:
fn takes_array_ref<T, const N: usize>(array: &&[T; N]) {
takes_slice(*array) // clippy suggests to remove dereference
}
fn takes_slice<T>(slice: &[T]) {
todo!()
}
I saw this happen:
--> src/lib.rs:2:17
|
2 | takes_slice(*array)
| ^^^^^^ help: try this: `array`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
= note: `#[warn(clippy::explicit_auto_deref)]` on by default
I expected to see this happen:
No lint, or a suggestion that builds
Version
rustc 1.67.0-nightly (6284998a2 2022-11-12)
binary: rustc
commit-hash: 6284998a2677d7e3e8420db783f3aa4fd80d7423
commit-date: 2022-11-12
host: aarch64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the Rust reproducer and confirming the explicit_auto_deref diagnostic and replacement suggestion. Then inspect the explicit_auto_deref lint implementation and its suggestion logic; done means the lint is suppressed for this case or emits a replacement that compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100