Skip to content

Explicit auto deref leads type inference to using unsized types in collections #16179

@ginnyTheCat

Description

@ginnyTheCat

Summary

In the reproducer I used a HashMap, but it also works with arrays for example. Removing the * as the suggestion suggests causes the compiler to infer that seen: HashMap<u8, str> which is invalid.

I'm not sure whether this is a duplicate of #9841 or sth new.

Lint Name

explicit_auto_deref

Reproducer

I tried this code:

#![warn(clippy::explicit_auto_deref)]

use std::collections::HashMap;

pub struct Word<'a>(pub &'a str);

pub fn seen_words<'a>() -> Vec<Word<'a>> {
    let seen: HashMap<u8, _> = HashMap::new();
    seen.values().map(|s| Word(*s)).collect()
}

I saw this happen:

warning: deref which would be done by auto-deref
 --> src/lib.rs:9:32
  |
9 |     seen.values().map(|s| Word(*s)).collect()
  |                                ^^ help: try: `s`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::explicit_auto_deref)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `tmp` (lib) generated 1 warning (run `cargo clippy --fix --lib -p tmp` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s

I expected to see this happen:
no warning

Version

rustc 1.93.0-nightly (1d60f9e07 2025-12-01)
binary: rustc
commit-hash: 1d60f9e070c1039b263e0f035c0f03dfcc610d0f
commit-date: 2025-12-01
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Additional Labels

@rustbot label +I-suggestion-causes-error

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 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