diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index ac72345dad425..4f24a8bb75a0e 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 { @@ -1029,6 +1028,24 @@ where } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for HashMap +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 PartialEq for HashMap where diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 3299fd12e024e..27093c1a077b0 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 { @@ -932,6 +931,23 @@ where } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for HashSet +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 PartialEq for HashSet where