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