Skip to content

Wrong iter_kv_map quickfix involving flat_map. #16742

@iago-lito

Description

@iago-lito

Clippy fired iter_kv_map to fix the following:

use std::collections::BTreeMap;
fn f(d: &BTreeMap<u64, Vec<&'static str>>) {
    let it = d.iter().flat_map(|(_, e)| e); // <- `iter_kv_map`
    for i in it {
        println!("{i}");
    }
}

into the following:

d.values()

But it is wrong. I guess the expected result would be:

d.values().flatten()

instead ?

Possibly related: #16515 ?

$ rustc -Vv
rustc 1.96.0-nightly (1e2183119 2026-03-15)
binary: rustc
commit-hash: 1e2183119f0ee19cc26df899e26b04ad0de3475d
commit-date: 2026-03-15
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

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 have

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions