Add test case

This commit is contained in:
Takayuki Nakata 2020-10-25 23:55:41 +09:00
parent 3ce820bf83
commit 2f5d418011
2 changed files with 20 additions and 1 deletions

View file

@ -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);
}

View file

@ -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