]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_hasher.rs
Merge pull request #3265 from mikerite/fix-export
[rust.git] / tests / ui / implicit_hasher.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11 #![allow(unused)]
12
13 use std::collections::{HashMap, HashSet};
14 use std::cmp::Eq;
15 use std::hash::{Hash, BuildHasher};
16
17 pub trait Foo<T>: Sized {
18     fn make() -> (Self, Self);
19 }
20
21 impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
22     fn make() -> (Self, Self) {
23         // OK, don't suggest to modify these
24         let _: HashMap<i32, i32> = HashMap::new();
25         let _: HashSet<i32> = HashSet::new();
26
27         (HashMap::new(), HashMap::with_capacity(10))
28     }
29 }
30 impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
31     fn make() -> (Self, Self) {
32         ((HashMap::new(),), (HashMap::with_capacity(10),))
33     }
34 }
35 impl Foo<i16> for HashMap<String, String> {
36     fn make() -> (Self, Self) {
37         (HashMap::new(), HashMap::with_capacity(10))
38     }
39 }
40
41 impl<K: Hash + Eq, V, S: BuildHasher + Default> Foo<i32> for HashMap<K, V, S> {
42     fn make() -> (Self, Self) {
43         (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
44     }
45 }
46 impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> {
47     fn make() -> (Self, Self) {
48         (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
49     }
50 }
51
52
53 impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
54     fn make() -> (Self, Self) {
55         (HashSet::new(), HashSet::with_capacity(10))
56     }
57 }
58 impl Foo<i16> for HashSet<String> {
59     fn make() -> (Self, Self) {
60         (HashSet::new(), HashSet::with_capacity(10))
61     }
62 }
63
64 impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> {
65     fn make() -> (Self, Self) {
66         (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
67     }
68 }
69 impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
70     fn make() -> (Self, Self) {
71         (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
72     }
73 }
74
75 pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
76 }
77
78 macro_rules! gen {
79     (impl) => {
80         impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
81             fn make() -> (Self, Self) {
82                 (HashMap::new(), HashMap::with_capacity(10))
83             }
84         }
85     };
86
87     (fn $name:ident) => {
88         pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
89         }
90     }
91 }
92
93 gen!(impl);
94 gen!(fn bar);
95
96 // When the macro is in a different file, the suggestion spans can't be combined properly
97 // and should not cause an ICE
98 // See #2707
99 #[macro_use]
100 #[path = "../auxiliary/test_macro.rs"] pub mod test_macro;
101 __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
102
103 fn main() {}