.into_iter()
.map(|x| (*x, *x + 1))
.collect::<HashMap<_, _>>();
+
+ // #6202
+ let a = "a".to_string();
+ let sample = vec![a.clone(), "b".to_string(), "c".to_string()];
+ let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
+ non_copy_contains.contains(&a);
}
LL | sample.iter().any(|x| x == &5);
|
-error: aborting due to 4 previous errors
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect_indirect.rs:23:5
+ |
+LL | / let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
+LL | | non_copy_contains.contains(&a);
+ | |____^
+ |
+help: Check if the original Iterator contains an element instead of collecting then checking
+ |
+LL |
+LL | sample.into_iter().any(|x| x == a);
+ |
+
+error: aborting due to 5 previous errors