]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/iter_count.fixed
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / iter_count.fixed
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[..].len();
55     vec.len();
56     boxed_slice.len();
57     vec_deque.len();
58     hash_set.len();
59     hash_map.len();
60     b_tree_map.len();
61     b_tree_set.len();
62     linked_list.len();
63     binary_heap.len();
64
65     vec.len();
66     &vec[..].len();
67     vec_deque.len();
68     hash_map.len();
69     b_tree_map.len();
70     linked_list.len();
71
72     &vec[..].len();
73     vec.len();
74     vec_deque.len();
75     hash_set.len();
76     hash_map.len();
77     b_tree_map.len();
78     b_tree_set.len();
79     linked_list.len();
80     binary_heap.len();
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 }