]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/implicit_hasher.rs
Rollup merge of #90538 - camelid:doc-recur-ty, r=estebank
[rust.git] / src / tools / clippy / tests / ui / implicit_hasher.rs
1 // aux-build:implicit_hasher_macros.rs
2 #![deny(clippy::implicit_hasher)]
3 #![allow(unused)]
4
5 #[macro_use]
6 extern crate implicit_hasher_macros;
7
8 use std::cmp::Eq;
9 use std::collections::{HashMap, HashSet};
10 use std::hash::{BuildHasher, Hash};
11
12 pub trait Foo<T>: Sized {
13     fn make() -> (Self, Self);
14 }
15
16 impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
17     fn make() -> (Self, Self) {
18         // OK, don't suggest to modify these
19         let _: HashMap<i32, i32> = HashMap::new();
20         let _: HashSet<i32> = HashSet::new();
21
22         (HashMap::new(), HashMap::with_capacity(10))
23     }
24 }
25 impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
26     fn make() -> (Self, Self) {
27         ((HashMap::new(),), (HashMap::with_capacity(10),))
28     }
29 }
30 impl Foo<i16> for HashMap<String, String> {
31     fn make() -> (Self, Self) {
32         (HashMap::new(), HashMap::with_capacity(10))
33     }
34 }
35
36 impl<K: Hash + Eq, V, S: BuildHasher + Default> Foo<i32> for HashMap<K, V, S> {
37     fn make() -> (Self, Self) {
38         (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
39     }
40 }
41 impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> {
42     fn make() -> (Self, Self) {
43         (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
44     }
45 }
46
47 impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
48     fn make() -> (Self, Self) {
49         (HashSet::new(), HashSet::with_capacity(10))
50     }
51 }
52 impl Foo<i16> for HashSet<String> {
53     fn make() -> (Self, Self) {
54         (HashSet::new(), HashSet::with_capacity(10))
55     }
56 }
57
58 impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> {
59     fn make() -> (Self, Self) {
60         (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
61     }
62 }
63 impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
64     fn make() -> (Self, Self) {
65         (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
66     }
67 }
68
69 pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
70
71 macro_rules! gen {
72     (impl) => {
73         impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
74             fn make() -> (Self, Self) {
75                 (HashMap::new(), HashMap::with_capacity(10))
76             }
77         }
78     };
79
80     (fn $name:ident) => {
81         pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
82     };
83 }
84 #[rustfmt::skip]
85 gen!(impl);
86 gen!(fn bar);
87
88 // When the macro is in a different file, the suggestion spans can't be combined properly
89 // and should not cause an ICE
90 // See #2707
91 #[macro_use]
92 #[path = "auxiliary/test_macro.rs"]
93 pub mod test_macro;
94 __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
95
96 // #4260
97 implicit_hasher_fn!();
98
99 // #7712
100 pub async fn election_vote(_data: HashMap<i32, i32>) {}
101
102 fn main() {}