Skip to content

Clippy fails to report .values() over .iter().map(|(_, v)| v) through .as_ref() #14595

@ThatGeoGuy

Description

@ThatGeoGuy

Summary

Clippy appears to fail to suggest iter_kv_map when going through a reference.

Lint Name

iter_kv_map

Reproducer

I tried this code:

pub struct Foo(BTreeMap<String, i32>);

impl AsRef<BTreeMap<String, i32>> for Foo {
    fn as_ref(&self) -> &BTreeMap<String, i32> {
        &self.0
    }
}

// Later

let foo = Foo(BTreeMap::default());

let values = foo
    .as_ref()
    .iter()
    .map(|(_, v)| v)
    .copied()
    .collect::<Vec<_>>();

I expected to see this happen:

libraries/silhouette/src/least_squares/parametric_problem.rs|252 col 23 error| iterating on a map's values
||     |
|| 252 |         let _values = foo.iter().map(|(_, v)| v).copied().collect::<Vec<_>>();
||     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo.values()`

Instead, this happened:

Nothing, no lint.

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions