Skip to content

Commit a2eb1f3

Browse files
committed
Add Ord trait bound on impl Clone for BTreeMap and BTreeSet
1 parent 083b5a0 commit a2eb1f3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/liballoc/collections/btree/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
135135
}
136136

137137
#[stable(feature = "rust1", since = "1.0.0")]
138-
impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
138+
impl<K: Clone + Ord, V: Clone> Clone for BTreeMap<K, V> {
139139
fn clone(&self) -> BTreeMap<K, V> {
140140
fn clone_subtree<'a, K: Clone, V: Clone>(
141141
node: node::NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>

src/liballoc/collections/btree/set.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ use super::Recover;
5656
/// println!("{}", book);
5757
/// }
5858
/// ```
59-
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
59+
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
6060
#[stable(feature = "rust1", since = "1.0.0")]
6161
pub struct BTreeSet<T> {
6262
map: BTreeMap<T, ()>,
6363
}
6464

65+
#[stable(feature = "rust1", since = "1.0.0")]
66+
impl<T: Clone + Ord> Clone for BTreeSet<T> {
67+
fn clone(&self) -> Self {
68+
BTreeSet { map: self.map.clone() }
69+
}
70+
71+
fn clone_from(&mut self, other: &Self) {
72+
self.map.clone_from(&other.map);
73+
}
74+
}
75+
6576
/// An iterator over the items of a `BTreeSet`.
6677
///
6778
/// This `struct` is created by the [`iter`] method on [`BTreeSet`].

0 commit comments

Comments
 (0)