mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Add test case
This commit is contained in:
parent
3ce820bf83
commit
2f5d418011
2 changed files with 20 additions and 1 deletions
|
@ -16,4 +16,10 @@ fn main() {
|
|||
.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);
|
||||
}
|
||||
|
|
|
@ -51,5 +51,18 @@ LL |
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue