Skip to content

explicit_auto_deref suggestion leads to non compiling code #9101

Closed
@jonasbb

Description

@jonasbb

Summary

The new explicit_auto_deref creates suggestions which do not compile. The lint already got ignored in serde serde-rs/serde@0ee71c7.

Lint Name

explicit_auto_deref

Reproducer

I tried this code:

use serde::Serializer;

fn serialize<S, const N: usize>(bytes: &&[u8; N], serializer: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    serializer.serialize_bytes(*bytes)
}

Playground

I saw this happen:

warning: deref which would be done by auto-deref
 --> src/lib.rs:7:32
  |
7 |     serializer.serialize_bytes(*bytes)
  |                                ^^^^^^ help: try this: `bytes`
  |
  = note: `#[warn(clippy::explicit_auto_deref)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

I expected to see this happen:

No lint should be emitted, since otherwise the function does not compile.

error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
   --> src/lib.rs:7:32
    |
7   |     serializer.serialize_bytes(bytes)
    |                --------------- ^^^^^ expected slice `[u8]`, found `&[u8; N]`
    |                |
    |                arguments to this function are incorrect
    |
    = note: expected reference `&[u8]`
               found reference `&&[u8; N]`
note: associated function defined here
   --> /playground/.cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/serde-1.0.137/src/ser/mod.rs:737:8
    |
737 |     fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
    |        ^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

Version

Rust nightly clippy on the Playground.
clippy 0.1.64 (2022-07-01 46b8c23)

Build using the Nightly version: 1.64.0-nightly
(2022-07-01 46b8c23f3eb5e4d0e0aa)

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions