make BuildHasher object safe

This commit is contained in:
ibraheemdev 2021-08-14 00:02:02 -04:00
parent d0a10b2056
commit 481b282e8a
2 changed files with 14 additions and 1 deletions

View file

@ -520,7 +520,10 @@ pub trait BuildHasher {
/// );
/// ```
#[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")]
fn hash_one<T: Hash>(&self, x: T) -> u64 {
fn hash_one<T: Hash>(&self, x: T) -> u64
where
Self: Sized,
{
let mut hasher = self.build_hasher();
x.hash(&mut hasher);
hasher.finish()

View file

@ -0,0 +1,10 @@
// run-pass
use std::hash::BuildHasher;
use std::collections::hash_map::{DefaultHasher, RandomState};
fn ensure_object_safe(_: &dyn BuildHasher<Hasher = DefaultHasher>) {}
fn main() {
ensure_object_safe(&RandomState::new());
}