diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index 9dbefe0822e36..8dec643255f64 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -520,7 +520,10 @@ pub trait BuildHasher { /// ); /// ``` #[unstable(feature = "build_hasher_simple_hash_one", issue = "86161")] - fn hash_one(&self, x: T) -> u64 { + fn hash_one(&self, x: T) -> u64 + where + Self: Sized, + { let mut hasher = self.build_hasher(); x.hash(&mut hasher); hasher.finish() diff --git a/src/test/ui/build-hasher-object-safe.rs b/src/test/ui/build-hasher-object-safe.rs new file mode 100644 index 0000000000000..50ec8e5e8d96e --- /dev/null +++ b/src/test/ui/build-hasher-object-safe.rs @@ -0,0 +1,10 @@ +// run-pass + +use std::hash::BuildHasher; +use std::collections::hash_map::{DefaultHasher, RandomState}; + +fn ensure_object_safe(_: &dyn BuildHasher) {} + +fn main() { + ensure_object_safe(&RandomState::new()); +}