BTreeMap: remove Ord bound where it is absent elsewhere

This commit is contained in:
Stein Somers 2020-11-20 21:29:00 +01:00
parent cfba499271
commit 9066c736a2
4 changed files with 22 additions and 20 deletions

View File

@ -501,11 +501,8 @@ pub const fn new() -> 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.
@ -1226,10 +1223,7 @@ pub(super) fn drain_filter_inner(&mut self) -> DrainFilterInner<'_, 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() }
}
@ -1252,10 +1246,7 @@ pub fn into_keys(self) -> IntoKeys<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() }
}
}

View File

@ -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, ()>) {
@ -1726,7 +1733,13 @@ fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
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, ()>) {

View File

@ -457,10 +457,7 @@ pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, 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()
}

View File

@ -641,9 +641,10 @@ fn union<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl 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();
}