]> git.lizzy.rs Git - rust.git/blob - tests/ui/iter_count.rs
Auto merge of #7059 - camsteffen:filter-map, r=flip1995
[rust.git] / 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 fn main() {
37     let mut vec = vec![0, 1, 2, 3];
38     let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
39     let mut vec_deque: VecDeque<_> = vec.iter().cloned().collect();
40     let mut hash_set = HashSet::new();
41     let mut hash_map = HashMap::new();
42     let mut b_tree_map = BTreeMap::new();
43     let mut b_tree_set = BTreeSet::new();
44     let mut linked_list = LinkedList::new();
45     let mut binary_heap = BinaryHeap::new();
46     hash_set.insert(1);
47     hash_map.insert(1, 2);
48     b_tree_map.insert(1, 2);
49     b_tree_set.insert(1);
50     linked_list.push_back(1);
51     binary_heap.push(1);
52
53     &vec[..].iter().count();
54     vec.iter().count();
55     boxed_slice.iter().count();
56     vec_deque.iter().count();
57     hash_set.iter().count();
58     hash_map.iter().count();
59     b_tree_map.iter().count();
60     b_tree_set.iter().count();
61     linked_list.iter().count();
62     binary_heap.iter().count();
63
64     vec.iter_mut().count();
65     &vec[..].iter_mut().count();
66     vec_deque.iter_mut().count();
67     hash_map.iter_mut().count();
68     b_tree_map.iter_mut().count();
69     linked_list.iter_mut().count();
70
71     &vec[..].into_iter().count();
72     vec.into_iter().count();
73     vec_deque.into_iter().count();
74     hash_set.into_iter().count();
75     hash_map.into_iter().count();
76     b_tree_map.into_iter().count();
77     b_tree_set.into_iter().count();
78     linked_list.into_iter().count();
79     binary_heap.into_iter().count();
80
81     // Make sure we don't lint for non-relevant types.
82     let false_positive = HasIter;
83     false_positive.iter().count();
84     false_positive.iter_mut().count();
85     false_positive.into_iter().count();
86 }