]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/implicit_hasher.rs
Auto merge of #6336 - giraffate:sync-from-rust, r=flip1995
[rust.git] / tests / ui / implicit_hasher.rs
index c93f858b5ca75d4d046f5cc21bec7cf8c0a96592..fdcc9a33f55fe93e2d5989f1757b2233c43c3d78 100644 (file)
@@ -1,8 +1,13 @@
+// aux-build:implicit_hasher_macros.rs
+#![deny(clippy::implicit_hasher)]
 #![allow(unused)]
 
-use std::collections::{HashMap, HashSet};
+#[macro_use]
+extern crate implicit_hasher_macros;
+
 use std::cmp::Eq;
-use std::hash::{Hash, BuildHasher};
+use std::collections::{HashMap, HashSet};
+use std::hash::{BuildHasher, Hash};
 
 pub trait Foo<T>: Sized {
     fn make() -> (Self, Self);
@@ -30,16 +35,15 @@ fn make() -> (Self, Self) {
 
 impl<K: Hash + Eq, V, S: BuildHasher + Default> Foo<i32> for HashMap<K, V, S> {
     fn make() -> (Self, Self) {
-        (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
+        (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
     }
 }
 impl<S: BuildHasher + Default> Foo<i64> for HashMap<String, String, S> {
     fn make() -> (Self, Self) {
-        (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
+        (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default()))
     }
 }
 
-
 impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
     fn make() -> (Self, Self) {
         (HashSet::new(), HashSet::with_capacity(10))
@@ -53,17 +57,16 @@ fn make() -> (Self, Self) {
 
 impl<T: Hash + Eq, S: BuildHasher + Default> Foo<i32> for HashSet<T, S> {
     fn make() -> (Self, Self) {
-        (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
+        (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
     }
 }
 impl<S: BuildHasher + Default> Foo<i64> for HashSet<String, S> {
     fn make() -> (Self, Self) {
-        (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
+        (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default()))
     }
 }
 
-pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
-}
+pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
 
 macro_rules! gen {
     (impl) => {
@@ -75,12 +78,22 @@ fn make() -> (Self, Self) {
     };
 
     (fn $name:ident) => {
-        pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
-        }
-    }
+        pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
+    };
 }
-
+#[rustfmt::skip]
 gen!(impl);
 gen!(fn bar);
 
+// 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]
+#[path = "../auxiliary/test_macro.rs"]
+pub mod test_macro;
+__implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
+
+// #4260
+implicit_hasher_fn!();
+
 fn main() {}