Remove the Ord bound that was plaguing drain_filter, and superfluous lifetimes

This commit is contained in:
Stein Somers 2020-04-06 15:18:05 +02:00
parent af89eb5e5b
commit 6ee7e8c978
2 changed files with 21 additions and 45 deletions

View File

@ -1699,28 +1699,22 @@ impl<K, V> Clone for Values<'_, K, V> {
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
pub struct DrainFilter<'a, K, V, F> pub struct DrainFilter<'a, K, V, F>
where where
K: 'a + Ord, // This Ord bound should be removed before stabilization. K: 'a,
V: 'a, V: 'a,
F: 'a + FnMut(&K, &mut V) -> bool, F: 'a + FnMut(&K, &mut V) -> bool,
{ {
pred: F, pred: F,
inner: DrainFilterInner<'a, K, V>, inner: DrainFilterInner<'a, K, V>,
} }
pub(super) struct DrainFilterInner<'a, K, V> pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> {
where
K: 'a + Ord,
V: 'a,
{
length: &'a mut usize, length: &'a mut usize,
cur_leaf_edge: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>, cur_leaf_edge: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>,
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, K, V, F> Drop for DrainFilter<'a, K, V, F> impl<K, V, F> Drop for DrainFilter<'_, K, V, F>
where where
K: 'a + Ord, F: FnMut(&K, &mut V) -> bool,
V: 'a,
F: 'a + FnMut(&K, &mut V) -> bool,
{ {
fn drop(&mut self) { fn drop(&mut self) {
self.for_each(drop); self.for_each(drop);
@ -1728,11 +1722,11 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, K, V, F> fmt::Debug for DrainFilter<'a, K, V, F> impl<K, V, F> fmt::Debug for DrainFilter<'_, K, V, F>
where where
K: 'a + fmt::Debug + Ord, K: fmt::Debug,
V: 'a + fmt::Debug, V: fmt::Debug,
F: 'a + FnMut(&K, &mut V) -> bool, F: FnMut(&K, &mut V) -> bool,
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("DrainFilter").field(&self.inner.peek()).finish() f.debug_tuple("DrainFilter").field(&self.inner.peek()).finish()
@ -1740,11 +1734,9 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, K, V, F> Iterator for DrainFilter<'a, K, V, F> impl<K, V, F> Iterator for DrainFilter<'_, K, V, F>
where where
K: 'a + Ord, F: FnMut(&K, &mut V) -> bool,
V: 'a,
F: 'a + FnMut(&K, &mut V) -> bool,
{ {
type Item = (K, V); type Item = (K, V);
@ -1757,11 +1749,7 @@ where
} }
} }
impl<'a, K, V> DrainFilterInner<'a, K, V> impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
where
K: 'a + Ord,
V: 'a,
{
/// Allow Debug implementations to predict the next element. /// Allow Debug implementations to predict the next element.
pub(super) fn peek(&self) -> Option<(&K, &V)> { pub(super) fn peek(&self) -> Option<(&K, &V)> {
let edge = self.cur_leaf_edge.as_ref()?; let edge = self.cur_leaf_edge.as_ref()?;
@ -1800,12 +1788,7 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<K, V, F> FusedIterator for DrainFilter<'_, K, V, F> impl<K, V, F> FusedIterator for DrainFilter<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
where
K: Ord,
F: FnMut(&K, &mut V) -> bool,
{
}
#[stable(feature = "btree_range", since = "1.17.0")] #[stable(feature = "btree_range", since = "1.17.0")]
impl<'a, K, V> Iterator for Range<'a, K, V> { impl<'a, K, V> Iterator for Range<'a, K, V> {

View File

@ -1094,7 +1094,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> {
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
pub struct DrainFilter<'a, T, F> pub struct DrainFilter<'a, T, F>
where where
T: 'a + Ord, T: 'a,
F: 'a + FnMut(&T) -> bool, F: 'a + FnMut(&T) -> bool,
{ {
pred: F, pred: F,
@ -1102,10 +1102,9 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, T, F> Drop for DrainFilter<'a, T, F> impl<T, F> Drop for DrainFilter<'_, T, F>
where where
T: 'a + Ord, F: FnMut(&T) -> bool,
F: 'a + FnMut(&T) -> bool,
{ {
fn drop(&mut self) { fn drop(&mut self) {
self.for_each(drop); self.for_each(drop);
@ -1113,10 +1112,10 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, T, F> fmt::Debug for DrainFilter<'a, T, F> impl<T, F> fmt::Debug for DrainFilter<'_, T, F>
where where
T: 'a + Ord + fmt::Debug, T: fmt::Debug,
F: 'a + FnMut(&T) -> bool, F: FnMut(&T) -> bool,
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("DrainFilter").field(&self.inner.peek().map(|(k, _)| k)).finish() f.debug_tuple("DrainFilter").field(&self.inner.peek().map(|(k, _)| k)).finish()
@ -1124,10 +1123,9 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, 'f, T, F> Iterator for DrainFilter<'a, T, F> impl<'a, T, F> Iterator for DrainFilter<'_, T, F>
where where
T: 'a + Ord, F: 'a + FnMut(&T) -> bool,
F: 'a + 'f + FnMut(&T) -> bool,
{ {
type Item = T; type Item = T;
@ -1143,12 +1141,7 @@ where
} }
#[unstable(feature = "btree_drain_filter", issue = "70530")] #[unstable(feature = "btree_drain_filter", issue = "70530")]
impl<'a, T, F> FusedIterator for DrainFilter<'a, T, F> impl<T, F> FusedIterator for DrainFilter<'_, T, F> where F: FnMut(&T) -> bool {}
where
T: 'a + Ord,
F: 'a + FnMut(&T) -> bool,
{
}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BTreeSet<T> { impl<T: Ord> Extend<T> for BTreeSet<T> {