]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // run-rustfix |
2 | ||
3 | #![allow(unused, clippy::suspicious_map, clippy::iter_count)] | |
4 | ||
17df50a5 | 5 | use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; |
f20569fa XL |
6 | |
7 | #[warn(clippy::needless_collect)] | |
8 | #[allow(unused_variables, clippy::iter_cloned_collect, clippy::iter_next_slice)] | |
9 | fn main() { | |
10 | let sample = [1; 5]; | |
11 | let len = sample.iter().count(); | |
12 | if sample.iter().next().is_none() { | |
13 | // Empty | |
14 | } | |
15 | sample.iter().cloned().any(|x| x == 1); | |
17df50a5 XL |
16 | // #7164 HashMap's and BTreeMap's `len` usage should not be linted |
17 | sample.iter().map(|x| (x, x)).collect::<HashMap<_, _>>().len(); | |
18 | sample.iter().map(|x| (x, x)).collect::<BTreeMap<_, _>>().len(); | |
19 | ||
20 | sample.iter().map(|x| (x, x)).next().is_none(); | |
21 | sample.iter().map(|x| (x, x)).next().is_none(); | |
22 | ||
f20569fa XL |
23 | // Notice the `HashSet`--this should not be linted |
24 | sample.iter().collect::<HashSet<_>>().len(); | |
25 | // Neither should this | |
26 | sample.iter().collect::<BTreeSet<_>>().len(); | |
17df50a5 XL |
27 | |
28 | sample.iter().count(); | |
29 | sample.iter().next().is_none(); | |
30 | sample.iter().cloned().any(|x| x == 1); | |
31 | sample.iter().any(|x| x == &1); | |
32 | ||
33 | // `BinaryHeap` doesn't have `contains` method | |
34 | sample.iter().count(); | |
35 | sample.iter().next().is_none(); | |
f20569fa | 36 | } |