Skip to content

Commit

Permalink
BTreeMap: remove Ord bound where it is absent elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ssomers committed Feb 6, 2021
1 parent cfba499 commit 9066c73
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
17 changes: 4 additions & 13 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,8 @@ impl<K, V> BTreeMap<K, V> {
/// assert!(a.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self)
where
K: Ord,
{
*self = BTreeMap::new();
pub fn clear(&mut self) {
*self = BTreeMap { root: None, length: 0 };
}

/// Returns a reference to the value corresponding to the key.
Expand Down Expand Up @@ -1226,10 +1223,7 @@ impl<K, V> BTreeMap<K, V> {
/// ```
#[inline]
#[unstable(feature = "map_into_keys_values", issue = "75294")]
pub fn into_keys(self) -> IntoKeys<K, V>
where
K: Ord,
{
pub fn into_keys(self) -> IntoKeys<K, V> {
IntoKeys { inner: self.into_iter() }
}

Expand All @@ -1252,10 +1246,7 @@ impl<K, V> BTreeMap<K, V> {
/// ```
#[inline]
#[unstable(feature = "map_into_keys_values", issue = "75294")]
pub fn into_values(self) -> IntoValues<K, V>
where
K: Ord,
{
pub fn into_values(self) -> IntoValues<K, V> {
IntoValues { inner: self.into_iter() }
}
}
Expand Down
17 changes: 15 additions & 2 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,12 +1711,19 @@ fn test_ord_absence() {
fn map<K>(mut map: BTreeMap<K, ()>) {
map.is_empty();
map.len();
map.clear();
map.iter();
map.iter_mut();
map.keys();
map.values();
map.values_mut();
map.into_iter();
if true {
map.into_values();
} else if true {
map.into_iter();
} else {
map.into_keys();
}
}

fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
Expand All @@ -1726,7 +1733,13 @@ fn test_ord_absence() {
format!("{:?}", map.keys());
format!("{:?}", map.values());
format!("{:?}", map.values_mut());
format!("{:?}", map.into_iter());
if true {
format!("{:?}", map.into_iter());
} else if true {
format!("{:?}", map.into_keys());
} else {
format!("{:?}", map.into_values());
}
}

fn map_clone<K: Clone>(mut map: BTreeMap<K, ()>) {
Expand Down
5 changes: 1 addition & 4 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ impl<T> BTreeSet<T> {
/// assert!(v.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self)
where
T: Ord,
{
pub fn clear(&mut self) {
self.map.clear()
}

Expand Down
3 changes: 2 additions & 1 deletion library/alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,10 @@ fn test_send() {

#[allow(dead_code)]
fn test_ord_absence() {
fn set<K>(set: BTreeSet<K>) {
fn set<K>(mut set: BTreeSet<K>) {
set.is_empty();
set.len();
set.clear();
set.iter();
set.into_iter();
}
Expand Down

0 comments on commit 9066c73

Please sign in to comment.