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
This commit is contained in:
commit
0f42d47bd5
@ -195,7 +195,6 @@
|
|||||||
/// // use the values stored in map
|
/// // use the values stored in map
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct HashMap<K, V, S = RandomState> {
|
pub struct HashMap<K, V, S = RandomState> {
|
||||||
@ -1029,6 +1028,24 @@ pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<K, V, S> PartialEq for HashMap<K, V, S>
|
impl<K, V, S> PartialEq for HashMap<K, V, S>
|
||||||
where
|
where
|
||||||
|
@ -106,7 +106,6 @@
|
|||||||
/// [`HashMap`]: crate::collections::HashMap
|
/// [`HashMap`]: crate::collections::HashMap
|
||||||
/// [`RefCell`]: crate::cell::RefCell
|
/// [`RefCell`]: crate::cell::RefCell
|
||||||
/// [`Cell`]: crate::cell::Cell
|
/// [`Cell`]: crate::cell::Cell
|
||||||
#[derive(Clone)]
|
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct HashSet<T, S = RandomState> {
|
pub struct HashSet<T, S = RandomState> {
|
||||||
@ -932,6 +931,23 @@ pub fn retain<F>(&mut self, f: F)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T, S> PartialEq for HashSet<T, S>
|
impl<T, S> PartialEq for HashSet<T, S>
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user