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