1 // aux-build:implicit_hasher_macros.rs
2 #![deny(clippy::implicit_hasher)]
6 extern crate implicit_hasher_macros;
9 use std::collections::{HashMap, HashSet};
10 use std::hash::{BuildHasher, Hash};
12 pub trait Foo<T>: Sized {
13 fn make() -> (Self, Self);
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();
22 (HashMap::new(), HashMap::with_capacity(10))
25 impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
26 fn make() -> (Self, Self) {
27 ((HashMap::new(),), (HashMap::with_capacity(10),))
30 impl Foo<i16> for HashMap<String, String> {
31 fn make() -> (Self, Self) {
32 (HashMap::new(), HashMap::with_capacity(10))
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()))
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()))
47 impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
48 fn make() -> (Self, Self) {
49 (HashSet::new(), HashSet::with_capacity(10))
52 impl Foo<i16> for HashSet<String> {
53 fn make() -> (Self, Self) {
54 (HashSet::new(), HashSet::with_capacity(10))
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()))
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()))
69 pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
73 impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
74 fn make() -> (Self, Self) {
75 (HashMap::new(), HashMap::with_capacity(10))
81 pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
88 // When the macro is in a different file, the suggestion spans can't be combined properly
89 // and should not cause an ICE
92 #[path = "../auxiliary/test_macro.rs"]
94 __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
97 implicit_hasher_fn!();