From 9066c736a23c24f23fb46846e80a33c02bf4ab82 Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Fri, 20 Nov 2020 21:29:00 +0100 Subject: [PATCH] BTreeMap: remove Ord bound where it is absent elsewhere --- library/alloc/src/collections/btree/map.rs | 17 ++++------------- .../alloc/src/collections/btree/map/tests.rs | 17 +++++++++++++++-- library/alloc/src/collections/btree/set.rs | 5 +---- .../alloc/src/collections/btree/set/tests.rs | 3 ++- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 946267d17c018..ebdc73f9eab1c 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -501,11 +501,8 @@ impl BTreeMap { /// 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. @@ -1226,10 +1223,7 @@ impl BTreeMap { /// ``` #[inline] #[unstable(feature = "map_into_keys_values", issue = "75294")] - pub fn into_keys(self) -> IntoKeys - where - K: Ord, - { + pub fn into_keys(self) -> IntoKeys { IntoKeys { inner: self.into_iter() } } @@ -1252,10 +1246,7 @@ impl BTreeMap { /// ``` #[inline] #[unstable(feature = "map_into_keys_values", issue = "75294")] - pub fn into_values(self) -> IntoValues - where - K: Ord, - { + pub fn into_values(self) -> IntoValues { IntoValues { inner: self.into_iter() } } } diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs index 78edf11d3934b..1993c6e047d48 100644 --- a/library/alloc/src/collections/btree/map/tests.rs +++ b/library/alloc/src/collections/btree/map/tests.rs @@ -1711,12 +1711,19 @@ fn test_ord_absence() { fn map(mut map: BTreeMap) { 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(mut map: BTreeMap) { @@ -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(mut map: BTreeMap) { diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index be4e50119c0d1..f7d8d14b86f15 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -457,10 +457,7 @@ impl BTreeSet { /// 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() } diff --git a/library/alloc/src/collections/btree/set/tests.rs b/library/alloc/src/collections/btree/set/tests.rs index 79e469eb0db8b..3762af7236af2 100644 --- a/library/alloc/src/collections/btree/set/tests.rs +++ b/library/alloc/src/collections/btree/set/tests.rs @@ -641,9 +641,10 @@ fn test_send() { #[allow(dead_code)] fn test_ord_absence() { - fn set(set: BTreeSet) { + fn set(mut set: BTreeSet) { set.is_empty(); set.len(); + set.clear(); set.iter(); set.into_iter(); }