]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/needless_collect.rs
Auto merge of #71751 - oli-obk:const_ice, r=RalfJung
[rust.git] / src / tools / clippy / tests / ui / needless_collect.rs
1 // run-rustfix
2
3 #![allow(unused, clippy::suspicious_map)]
4
5 use std::collections::{BTreeSet, HashMap, HashSet};
6
7 #[warn(clippy::needless_collect)]
8 #[allow(unused_variables, clippy::iter_cloned_collect)]
9 fn main() {
10     let sample = [1; 5];
11     let len = sample.iter().collect::<Vec<_>>().len();
12     if sample.iter().collect::<Vec<_>>().is_empty() {
13         // Empty
14     }
15     sample.iter().cloned().collect::<Vec<_>>().contains(&1);
16     sample.iter().map(|x| (x, x)).collect::<HashMap<_, _>>().len();
17     // Notice the `HashSet`--this should not be linted
18     sample.iter().collect::<HashSet<_>>().len();
19     // Neither should this
20     sample.iter().collect::<BTreeSet<_>>().len();
21 }