]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/needless_collect.fixed
Rollup merge of #98609 - TaKO8Ki:fix-ice-for-associated-constant-generics, r=lcnr
[rust.git] / src / tools / clippy / tests / ui / needless_collect.fixed
1 // run-rustfix
2
3 #![allow(unused, clippy::suspicious_map, clippy::iter_count)]
4
5 use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList};
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);
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
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();
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();
36 }