]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_hasher.rs
Merge pull request #2713 from alexreg/nightly-fix
[rust.git] / tests / ui / implicit_hasher.rs
1 #![allow(unused)]
2
3 use std::collections::{HashMap, HashSet};
4 use std::cmp::Eq;
5 use std::hash::{Hash, BuildHasher};
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, Default::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, Default::default()))
39     }
40 }
41
42
43 impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
44     fn make() -> (Self, Self) {
45         (HashSet::new(), HashSet::with_capacity(10))
46     }
47 }
48 impl Foo<i16> for HashSet<String> {
49     fn make() -> (Self, Self) {
50         (HashSet::new(), HashSet::with_capacity(10))
51     }
52 }
53
54 impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> {
55     fn make() -> (Self, Self) {
56         (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
57     }
58 }
59 impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
60     fn make() -> (Self, Self) {
61         (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
62     }
63 }
64
65 pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
66 }
67
68 macro_rules! gen {
69     (impl) => {
70         impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
71             fn make() -> (Self, Self) {
72                 (HashMap::new(), HashMap::with_capacity(10))
73             }
74         }
75     };
76
77     (fn $name:ident) => {
78         pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
79         }
80     }
81 }
82
83 gen!(impl);
84 gen!(fn bar);
85
86 // When the macro is in a different file, the suggestion spans can't be combined properly
87 // and should not cause an ICE
88 // See #2707
89 #[macro_use]
90 #[path = "../auxiliary/test_macro.rs"] pub mod test_macro;
91 __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
92
93 fn main() {}