Skip to content

Commit ef752e4

Browse files
committed
Auto merge of #291 - cuviper:hasher, r=cuviper
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. (extends #287)
2 parents f9d36e6 + 1b895a8 commit ef752e4

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 = hash::SipHasher::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 = hash::SipHasher::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
@@ -843,8 +843,9 @@ fn approximate_float_unsigned<T, F>(val: F, max_error: F, max_iterations: usize)
843843

844844
#[cfg(test)]
845845
fn hash<T: hash::Hash>(x: &T) -> u64 {
846-
use std::hash::Hasher;
847-
let mut hasher = hash::SipHasher::new();
846+
use std::hash::{BuildHasher, Hasher};
847+
use std::collections::hash_map::RandomState;
848+
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
848849
x.hash(&mut hasher);
849850
hasher.finish()
850851
}

0 commit comments

Comments
 (0)