From c270e27a4d37f008c199523f223843e8659b7fd9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 16 Nov 2024 12:22:47 -0800 Subject: [PATCH] Use BuildHasher instead of Hasher in collection macros --- test_suite/tests/macros/mod.rs | 10 ++++------ test_suite/tests/test_de.rs | 6 +++--- test_suite/tests/test_ser.rs | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/test_suite/tests/macros/mod.rs b/test_suite/tests/macros/mod.rs index d66324464..44b98ae2f 100644 --- a/test_suite/tests/macros/mod.rs +++ b/test_suite/tests/macros/mod.rs @@ -34,9 +34,8 @@ macro_rules! hashset { $(set.insert($value);)+ set }}; - ($hasher:ident @ $($value:expr),+) => {{ - use std::hash::BuildHasherDefault; - let mut set = HashSet::with_hasher(BuildHasherDefault::<$hasher>::default()); + ($hasher:ty; $($value:expr),+) => {{ + let mut set = HashSet::<_, $hasher>::default(); $(set.insert($value);)+ set }}; @@ -51,9 +50,8 @@ macro_rules! hashmap { $(map.insert($key, $value);)+ map }}; - ($hasher:ident @ $($key:expr => $value:expr),+) => {{ - use std::hash::BuildHasherDefault; - let mut map = HashMap::with_hasher(BuildHasherDefault::<$hasher>::default()); + ($hasher:ty; $($key:expr => $value:expr),+) => {{ + let mut map = HashMap::<_, _, $hasher>::default(); $(map.insert($key, $value);)+ map }}; diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index 31e726d4b..9726ef543 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -10,7 +10,7 @@ )] #![cfg_attr(feature = "unstable", feature(never_type))] -use fnv::FnvHasher; +use fnv::FnvBuildHasher; use serde::de::value::{F32Deserializer, F64Deserializer}; use serde::de::{Deserialize, DeserializeOwned, Deserializer, IntoDeserializer}; use serde_derive::Deserialize; @@ -1040,7 +1040,7 @@ fn test_hashset() { ], ); test( - hashset![FnvHasher @ 1, 2, 3], + hashset![FnvBuildHasher; 1, 2, 3], &[ Token::Seq { len: Some(3) }, Token::I32(1), @@ -1275,7 +1275,7 @@ fn test_hashmap() { ], ); test( - hashmap![FnvHasher @ 1 => 2, 3 => 4], + hashmap![FnvBuildHasher; 1 => 2, 3 => 4], &[ Token::Map { len: Some(2) }, Token::I32(1), diff --git a/test_suite/tests/test_ser.rs b/test_suite/tests/test_ser.rs index b60d03ab2..0a1c1ee97 100644 --- a/test_suite/tests/test_ser.rs +++ b/test_suite/tests/test_ser.rs @@ -1,7 +1,7 @@ #![allow(clippy::derive_partial_eq_without_eq, clippy::unreadable_literal)] #![cfg_attr(feature = "unstable", feature(never_type))] -use fnv::FnvHasher; +use fnv::FnvBuildHasher; use serde_derive::Serialize; use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token}; use std::cell::RefCell; @@ -220,7 +220,7 @@ fn test_hashset() { &[Token::Seq { len: Some(1) }, Token::I32(1), Token::SeqEnd], ); assert_ser_tokens( - &hashset![FnvHasher @ 1], + &hashset![FnvBuildHasher; 1], &[Token::Seq { len: Some(1) }, Token::I32(1), Token::SeqEnd], ); } @@ -300,7 +300,7 @@ fn test_hashmap() { ], ); assert_ser_tokens( - &hashmap![FnvHasher @ 1 => 2], + &hashmap![FnvBuildHasher; 1 => 2], &[ Token::Map { len: Some(1) }, Token::I32(1),