about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-27 04:14:20 +0000
committerbors <bors@rust-lang.org>2020-12-27 04:14:20 +0000
commit0f42d47bd5352028fe297f5e759b7e3763d55cbb (patch)
tree210c230bc984abd71515fa5638464810809eb8b0
parent7e0246552facb87995fb2ee6b211b9ffd05b4c62 (diff)
parent7adeb710fbb1cc27e4c098c3dbdf249f59e16065 (diff)
downloadrust-0f42d47bd5352028fe297f5e759b7e3763d55cbb.tar.gz
rust-0f42d47bd5352028fe297f5e759b7e3763d55cbb.zip
Auto merge of #80400 - adlerd:hashclone, r=Mark-Simulacrum
Use `clone_from` from `hashbrown::{HashMap,HashSet}`.

This change updates the `std` hash collections to use `hashbrown`'s `clone_from`, which was itself added in #70052. Deriving `Clone` does not add a `clone_from` impl and uses the trait default, which calls `clone`.

Fixes #28481
-rw-r--r--library/std/src/collections/hash/map.rs19
-rw-r--r--library/std/src/collections/hash/set.rs18
2 files changed, 35 insertions, 2 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs
index ac72345dad4..4f24a8bb75a 100644
--- a/library/std/src/collections/hash/map.rs
+++ b/library/std/src/collections/hash/map.rs
@@ -195,7 +195,6 @@ use crate::sys;
 /// // use the values stored in map
 /// ```
 
-#[derive(Clone)]
 #[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct HashMap<K, V, S = RandomState> {
@@ -1030,6 +1029,24 @@ where
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+impl<K, V, S> Clone for HashMap<K, V, S>
+where
+    K: Clone,
+    V: Clone,
+    S: Clone,
+{
+    #[inline]
+    fn clone(&self) -> Self {
+        Self { base: self.base.clone() }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, other: &Self) {
+        self.base.clone_from(&other.base);
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<K, V, S> PartialEq for HashMap<K, V, S>
 where
     K: Eq + Hash,
diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs
index 3299fd12e02..27093c1a077 100644
--- a/library/std/src/collections/hash/set.rs
+++ b/library/std/src/collections/hash/set.rs
@@ -106,7 +106,6 @@ use super::map::{map_try_reserve_error, RandomState};
 /// [`HashMap`]: crate::collections::HashMap
 /// [`RefCell`]: crate::cell::RefCell
 /// [`Cell`]: crate::cell::Cell
-#[derive(Clone)]
 #[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct HashSet<T, S = RandomState> {
@@ -933,6 +932,23 @@ where
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+impl<T, S> Clone for HashSet<T, S>
+where
+    T: Clone,
+    S: Clone,
+{
+    #[inline]
+    fn clone(&self) -> Self {
+        Self { base: self.base.clone() }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, other: &Self) {
+        self.base.clone_from(&other.base);
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T, S> PartialEq for HashSet<T, S>
 where
     T: Eq + Hash,