2019-07-11 01:47:05 -05:00
|
|
|
// aux-build:implicit_hasher_macros.rs
|
2020-04-02 21:09:30 -05:00
|
|
|
#![deny(clippy::implicit_hasher)]
|
2017-10-05 09:57:31 -05:00
|
|
|
#![allow(unused)]
|
2017-11-14 07:56:00 -06:00
|
|
|
|
2019-07-11 01:47:05 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate implicit_hasher_macros;
|
|
|
|
|
2017-10-05 09:57:31 -05:00
|
|
|
use std::cmp::Eq;
|
2018-12-09 16:26:16 -06:00
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
use std::hash::{BuildHasher, Hash};
|
2017-10-05 09:57:31 -05:00
|
|
|
|
2017-10-17 07:12:31 -05:00
|
|
|
pub trait Foo<T>: Sized {
|
2017-10-05 09:57:31 -05:00
|
|
|
fn make() -> (Self, Self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
// OK, don't suggest to modify these
|
|
|
|
let _: HashMap<i32, i32> = HashMap::new();
|
|
|
|
let _: HashSet<i32> = HashSet::new();
|
|
|
|
|
|
|
|
(HashMap::new(), HashMap::with_capacity(10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
((HashMap::new(),), (HashMap::with_capacity(10),))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Foo<i16> for HashMap<String, String> {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
(HashMap::new(), HashMap::with_capacity(10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<K: Hash + Eq, V, S: BuildHasher + Default> Foo<i32> for HashMap<K, V, S> {
|
|
|
|
fn make() -> (Self, Self) {
|
2018-06-14 17:13:12 -05:00
|
|
|
(HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
|
2017-10-05 09:57:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> {
|
|
|
|
fn make() -> (Self, Self) {
|
2018-06-14 17:13:12 -05:00
|
|
|
(HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
|
2017-10-05 09:57:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
(HashSet::new(), HashSet::with_capacity(10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Foo<i16> for HashSet<String> {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
(HashSet::new(), HashSet::with_capacity(10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> {
|
|
|
|
fn make() -> (Self, Self) {
|
2018-06-14 17:13:12 -05:00
|
|
|
(HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
|
2017-10-05 09:57:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
|
|
|
|
fn make() -> (Self, Self) {
|
2018-06-14 17:13:12 -05:00
|
|
|
(HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
|
2017-10-05 09:57:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
|
2017-10-05 09:57:31 -05:00
|
|
|
|
2017-10-10 22:10:10 -05:00
|
|
|
macro_rules! gen {
|
|
|
|
(impl) => {
|
|
|
|
impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
|
|
|
|
fn make() -> (Self, Self) {
|
|
|
|
(HashMap::new(), HashMap::with_capacity(10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(fn $name:ident) => {
|
2018-12-09 16:26:16 -06:00
|
|
|
pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
|
|
|
|
};
|
2017-10-10 22:10:10 -05:00
|
|
|
}
|
2018-12-11 13:50:55 -06:00
|
|
|
#[rustfmt::skip]
|
|
|
|
gen!(impl);
|
2017-10-10 22:10:10 -05:00
|
|
|
gen!(fn bar);
|
|
|
|
|
2018-05-01 08:01:28 -05:00
|
|
|
// When the macro is in a different file, the suggestion spans can't be combined properly
|
|
|
|
// and should not cause an ICE
|
|
|
|
// See #2707
|
|
|
|
#[macro_use]
|
2021-07-30 22:43:04 -05:00
|
|
|
#[path = "auxiliary/test_macro.rs"]
|
2018-12-09 16:26:16 -06:00
|
|
|
pub mod test_macro;
|
2018-05-01 08:01:28 -05:00
|
|
|
__implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
|
|
|
|
|
2019-07-11 01:47:05 -05:00
|
|
|
// #4260
|
|
|
|
implicit_hasher_fn!();
|
|
|
|
|
2021-10-04 09:31:40 -05:00
|
|
|
// #7712
|
|
|
|
pub async fn election_vote(_data: HashMap<i32, i32>) {}
|
|
|
|
|
2017-10-05 09:57:31 -05:00
|
|
|
fn main() {}
|