-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
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 thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't