diff --git a/src/map.rs b/src/map.rs index 60ff344f8a..11e1a14a13 100644 --- a/src/map.rs +++ b/src/map.rs @@ -202,41 +202,10 @@ impl Clone for HashMap { } fn clone_from(&mut self, source: &Self) { - // We clone the hash_builder first since this might panic and we don't - // want the table to have elements hashed with the wrong hash_builder. - let hash_builder = source.hash_builder.clone(); - - // For backward-compatibility reasons we can't make the Clone impl - // depend on K: Hash + Eq and S: BuildHasher. However we can exploit - // this using specialization, which allows us to reuse the existing - // storage of the current HashMap to insert the cloned elements into. - trait HashClone { - fn clone_from(&mut self, source: &Self, hash_builder: &S); - } - impl HashClone for HashMap { - #[cfg_attr(feature = "inline-more", inline)] - default_fn! { - fn clone_from(&mut self, source: &Self, _hash_builder: &S) { - self.table.clone_from(&source.table); - } - } - } - #[cfg(feature = "nightly")] - impl HashClone for HashMap - where - K: Eq + Hash, - S: BuildHasher, - { - #[cfg_attr(feature = "inline-more", inline)] - fn clone_from(&mut self, source: &Self, hash_builder: &S) { - self.table - .clone_from_with_hasher(&source.table, |x| make_hash(hash_builder, &x.0)); - } - } - HashClone::clone_from(self, source, &hash_builder); + self.table.clone_from(&source.table); // Update hash_builder only if we successfully cloned all elements. - self.hash_builder = hash_builder; + self.hash_builder.clone_from(&source.hash_builder); } }