Skip to content

Commit 1b895a8

Browse files
committed
Get the default hasher indirectly
`DefaultHasher` wasn't stable until 1.13, at which point all the other hashers were deprecated, so it's not easy for us to name a hasher type to use for testing. However, `RandomState` has been stable since 1.7, and it implements `BuildHasher` that has a `Hasher` associated type.
1 parent 71a1521 commit 1b895a8

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

bigint/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ use std::hash;
120120

121121
#[cfg(test)]
122122
fn hash<T: hash::Hash>(x: &T) -> u64 {
123-
use std::hash::Hasher;
124-
let mut hasher = std::collections::hash_map::DefaultHasher::new();
123+
use std::hash::{BuildHasher, Hasher};
124+
use std::collections::hash_map::RandomState;
125+
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
125126
x.hash(&mut hasher);
126127
hasher.finish()
127128
}

complex/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,9 @@ impl<T> serde::Deserialize for Complex<T> where
765765

766766
#[cfg(test)]
767767
fn hash<T: hash::Hash>(x: &T) -> u64 {
768-
use std::hash::Hasher;
769-
let mut hasher = std::collections::hash_map::DefaultHasher::new();
768+
use std::hash::{BuildHasher, Hasher};
769+
use std::collections::hash_map::RandomState;
770+
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
770771
x.hash(&mut hasher);
771772
hasher.finish()
772773
}

rational/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,9 @@ impl RatioErrorKind {
670670

671671
#[cfg(test)]
672672
fn hash<T: hash::Hash>(x: &T) -> u64 {
673-
use std::hash::Hasher;
674-
let mut hasher = std::collections::hash_map::DefaultHasher::new();
673+
use std::hash::{BuildHasher, Hasher};
674+
use std::collections::hash_map::RandomState;
675+
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
675676
x.hash(&mut hasher);
676677
hasher.finish()
677678
}

0 commit comments

Comments
 (0)