]>
Commit | Line | Data |
---|---|---|
f20569fa | 1 | error: avoid using `collect()` when not needed |
cdc7bbd5 | 2 | --> $DIR/needless_collect_indirect.rs:5:39 |
f20569fa | 3 | | |
cdc7bbd5 XL |
4 | LL | let indirect_iter = sample.iter().collect::<Vec<_>>(); |
5 | | ^^^^^^^ | |
6 | LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>(); | |
7 | | ------------------------- the iterator could be used here instead | |
f20569fa XL |
8 | | |
9 | = note: `-D clippy::needless-collect` implied by `-D warnings` | |
10 | help: use the original Iterator instead of collecting it and then producing a new one | |
11 | | | |
12 | LL | | |
13 | LL | sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>(); | |
14 | | | |
15 | ||
16 | error: avoid using `collect()` when not needed | |
cdc7bbd5 | 17 | --> $DIR/needless_collect_indirect.rs:7:38 |
f20569fa | 18 | | |
cdc7bbd5 XL |
19 | LL | let indirect_len = sample.iter().collect::<VecDeque<_>>(); |
20 | | ^^^^^^^ | |
21 | LL | indirect_len.len(); | |
22 | | ------------------ the iterator could be used here instead | |
f20569fa XL |
23 | | |
24 | help: take the original Iterator's count instead of collecting it and finding the length | |
25 | | | |
26 | LL | | |
27 | LL | sample.iter().count(); | |
28 | | | |
29 | ||
30 | error: avoid using `collect()` when not needed | |
cdc7bbd5 | 31 | --> $DIR/needless_collect_indirect.rs:9:40 |
f20569fa | 32 | | |
cdc7bbd5 XL |
33 | LL | let indirect_empty = sample.iter().collect::<VecDeque<_>>(); |
34 | | ^^^^^^^ | |
35 | LL | indirect_empty.is_empty(); | |
36 | | ------------------------- the iterator could be used here instead | |
f20569fa XL |
37 | | |
38 | help: check if the original Iterator has anything instead of collecting it and seeing if it's empty | |
39 | | | |
40 | LL | | |
41 | LL | sample.iter().next().is_none(); | |
42 | | | |
43 | ||
44 | error: avoid using `collect()` when not needed | |
cdc7bbd5 | 45 | --> $DIR/needless_collect_indirect.rs:11:43 |
f20569fa | 46 | | |
cdc7bbd5 XL |
47 | LL | let indirect_contains = sample.iter().collect::<VecDeque<_>>(); |
48 | | ^^^^^^^ | |
49 | LL | indirect_contains.contains(&&5); | |
50 | | ------------------------------- the iterator could be used here instead | |
f20569fa XL |
51 | | |
52 | help: check if the original Iterator contains an element instead of collecting then checking | |
53 | | | |
54 | LL | | |
55 | LL | sample.iter().any(|x| x == &5); | |
56 | | | |
57 | ||
58 | error: avoid using `collect()` when not needed | |
cdc7bbd5 | 59 | --> $DIR/needless_collect_indirect.rs:23:48 |
f20569fa | 60 | | |
cdc7bbd5 XL |
61 | LL | let non_copy_contains = sample.into_iter().collect::<Vec<_>>(); |
62 | | ^^^^^^^ | |
63 | LL | non_copy_contains.contains(&a); | |
64 | | ------------------------------ the iterator could be used here instead | |
f20569fa XL |
65 | | |
66 | help: check if the original Iterator contains an element instead of collecting then checking | |
67 | | | |
68 | LL | | |
69 | LL | sample.into_iter().any(|x| x == a); | |
70 | | | |
71 | ||
72 | error: aborting due to 5 previous errors | |
73 |