]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/iter_count.rs
Rollup merge of #102625 - Rageking8:fix-backtrace-small-typo, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / iter_count.rs
1 // run-rustfix
2 // aux-build:option_helpers.rs
3
4 #![warn(clippy::iter_count)]
5 #![allow(
6     unused_variables,
7     array_into_iter,
8     unused_mut,
9     clippy::into_iter_on_ref,
10     clippy::unnecessary_operation
11 )]
12
13 extern crate option_helpers;
14
15 use option_helpers::IteratorFalsePositives;
16 use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
17
18 /// Struct to generate false positives for things with `.iter()`.
19 #[derive(Copy, Clone)]
20 struct HasIter;
21
22 impl HasIter {
23     fn iter(self) -> IteratorFalsePositives {
24         IteratorFalsePositives { foo: 0 }
25     }
26
27     fn iter_mut(self) -> IteratorFalsePositives {
28         IteratorFalsePositives { foo: 0 }
29     }
30
31     fn into_iter(self) -> IteratorFalsePositives {
32         IteratorFalsePositives { foo: 0 }
33     }
34 }
35
36 #[allow(unused_must_use)]
37 fn main() {
38     let mut vec = vec![0, 1, 2, 3];
39     let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
40     let mut vec_deque: VecDeque<_> = vec.iter().cloned().collect();
41     let mut hash_set = HashSet::new();
42     let mut hash_map = HashMap::new();
43     let mut b_tree_map = BTreeMap::new();
44     let mut b_tree_set = BTreeSet::new();
45     let mut linked_list = LinkedList::new();
46     let mut binary_heap = BinaryHeap::new();
47     hash_set.insert(1);
48     hash_map.insert(1, 2);
49     b_tree_map.insert(1, 2);
50     b_tree_set.insert(1);
51     linked_list.push_back(1);
52     binary_heap.push(1);
53
54     &vec[..].iter().count();
55     vec.iter().count();
56     boxed_slice.iter().count();
57     vec_deque.iter().count();
58     hash_set.iter().count();
59     hash_map.iter().count();
60     b_tree_map.iter().count();
61     b_tree_set.iter().count();
62     linked_list.iter().count();
63     binary_heap.iter().count();
64
65     vec.iter_mut().count();
66     &vec[..].iter_mut().count();
67     vec_deque.iter_mut().count();
68     hash_map.iter_mut().count();
69     b_tree_map.iter_mut().count();
70     linked_list.iter_mut().count();
71
72     &vec[..].into_iter().count();
73     vec.into_iter().count();
74     vec_deque.into_iter().count();
75     hash_set.into_iter().count();
76     hash_map.into_iter().count();
77     b_tree_map.into_iter().count();
78     b_tree_set.into_iter().count();
79     linked_list.into_iter().count();
80     binary_heap.into_iter().count();
81
82     // Make sure we don't lint for non-relevant types.
83     let false_positive = HasIter;
84     false_positive.iter().count();
85     false_positive.iter_mut().count();
86     false_positive.into_iter().count();
87 }