2 // aux-build:option_helpers.rs
4 #![warn(clippy::iter_count)]
9 clippy::into_iter_on_ref,
10 clippy::unnecessary_operation
13 extern crate option_helpers;
15 use option_helpers::IteratorFalsePositives;
16 use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
18 /// Struct to generate false positives for things with `.iter()`.
19 #[derive(Copy, Clone)]
23 fn iter(self) -> IteratorFalsePositives {
24 IteratorFalsePositives { foo: 0 }
27 fn iter_mut(self) -> IteratorFalsePositives {
28 IteratorFalsePositives { foo: 0 }
31 fn into_iter(self) -> IteratorFalsePositives {
32 IteratorFalsePositives { foo: 0 }
36 #[allow(unused_must_use)]
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();
48 hash_map.insert(1, 2);
49 b_tree_map.insert(1, 2);
51 linked_list.push_back(1);
54 &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();
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();
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();
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();