-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
as tittle
Lint Name
redundant_iter_cloned
Reproducer
I tried this code:
#[derive(Clone)]
struct Foo;
impl Foo {
async fn foo(&self) {}
}
let _futures = {
let map: HashMap<(), Foo> = HashMap::new();
map.values()
.cloned()
.map(|foo| async move { foo.foo().await })
.collect::<Vec<_>>()
};I saw this happen:
warning: unneeded cloning of iterator items
--> qconnection/src/traversal.rs:233:13
|
233 | / map.values()
234 | | .cloned()
235 | | .map(|foo| async move { foo.foo().await })
| |__________________________________________________________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_iter_cloned
help: try
|
233 ~ map.values()
234 + .map(|foo| async move { foo.foo().await })
|
Adopting the suggestion will cause a compilation error.
Interestingly, if Foo implements Copy, the warning will not appear.
Version
rustc 1.95.0-nightly (d940e5684 2026-01-19)
binary: rustc
commit-hash: d940e56841ddcc05671ead99290e35ff2e98369f
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8
Additional Labels
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have