Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ThatGeoGuy opened this issue Apr 11, 2025 · 1 comment · Fixed by #14596
Closed

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

ThatGeoGuy opened this issue Apr 11, 2025 · 1 comment · Fixed by #14596
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@ThatGeoGuy
Copy link

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
@ThatGeoGuy ThatGeoGuy added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Apr 11, 2025
@ThatGeoGuy
Copy link
Author

Feels related to #12142 but I honestly am not sure about that.

@samueltardieu samueltardieu self-assigned this Apr 11, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 21, 2025
Fix #14595

changelog: [`iter_kv_map`]: recognize references on maps as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants