Skip to content

Commit

Permalink
make BuildHasher object safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Aug 14, 2021
1 parent d0a10b2 commit 481b282
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/core/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/build-hasher-object-safe.rs
Original file line number Diff line number Diff line change
@@ -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());
}

0 comments on commit 481b282

Please sign in to comment.