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)
This commit is contained in:
Homu 2017-05-07 14:48:07 +09:00
commit ef752e4687
3 changed files with 9 additions and 6 deletions

View File

@ -120,8 +120,9 @@ use std::hash;
#[cfg(test)] #[cfg(test)]
fn hash<T: hash::Hash>(x: &T) -> u64 { fn hash<T: hash::Hash>(x: &T) -> u64 {
use std::hash::Hasher; use std::hash::{BuildHasher, Hasher};
let mut hasher = hash::SipHasher::new(); use std::collections::hash_map::RandomState;
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
x.hash(&mut hasher); x.hash(&mut hasher);
hasher.finish() hasher.finish()
} }

View File

@ -765,8 +765,9 @@ impl<T> serde::Deserialize for Complex<T> where
#[cfg(test)] #[cfg(test)]
fn hash<T: hash::Hash>(x: &T) -> u64 { fn hash<T: hash::Hash>(x: &T) -> u64 {
use std::hash::Hasher; use std::hash::{BuildHasher, Hasher};
let mut hasher = hash::SipHasher::new(); use std::collections::hash_map::RandomState;
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
x.hash(&mut hasher); x.hash(&mut hasher);
hasher.finish() hasher.finish()
} }

View File

@ -843,8 +843,9 @@ fn approximate_float_unsigned<T, F>(val: F, max_error: F, max_iterations: usize)
#[cfg(test)] #[cfg(test)]
fn hash<T: hash::Hash>(x: &T) -> u64 { fn hash<T: hash::Hash>(x: &T) -> u64 {
use std::hash::Hasher; use std::hash::{BuildHasher, Hasher};
let mut hasher = hash::SipHasher::new(); use std::collections::hash_map::RandomState;
let mut hasher = <RandomState as BuildHasher>::Hasher::new();
x.hash(&mut hasher); x.hash(&mut hasher);
hasher.finish() hasher.finish()
} }