Consistent trait bounds for ExtractIf Debug impls

This commit is contained in:
David Tolnay
2025-03-15 11:19:56 -07:00
parent cd55868a8d
commit c35914383a
7 changed files with 49 additions and 40 deletions
+5 -6
View File
@@ -1917,14 +1917,13 @@ pub struct ExtractIf<
V,
F,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
> where
F: 'a + FnMut(&K, &mut V) -> bool,
{
> {
pred: F,
inner: ExtractIfInner<'a, K, V>,
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
alloc: A,
}
/// Most of the implementation of ExtractIf are generic over the type
/// of the predicate, thus also serving for BTreeSet::ExtractIf.
pub(super) struct ExtractIfInner<'a, K, V> {
@@ -1940,14 +1939,14 @@ pub(super) struct ExtractIfInner<'a, K, V> {
}
#[unstable(feature = "btree_extract_if", issue = "70530")]
impl<K, V, F> fmt::Debug for ExtractIf<'_, K, V, F>
impl<K, V, F, A> fmt::Debug for ExtractIf<'_, K, V, F, A>
where
K: fmt::Debug,
V: fmt::Debug,
F: FnMut(&K, &mut V) -> bool,
A: Allocator + Clone,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ExtractIf").field(&self.inner.peek()).finish()
f.debug_struct("ExtractIf").field("peek", &self.inner.peek()).finish_non_exhaustive()
}
}
+6 -7
View File
@@ -1556,10 +1556,7 @@ pub struct ExtractIf<
T,
F,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
> where
T: 'a,
F: 'a + FnMut(&T) -> bool,
{
> {
pred: F,
inner: super::map::ExtractIfInner<'a, T, SetValZST>,
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
@@ -1567,13 +1564,15 @@ pub struct ExtractIf<
}
#[unstable(feature = "btree_extract_if", issue = "70530")]
impl<T, F, A: Allocator + Clone> fmt::Debug for ExtractIf<'_, T, F, A>
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
where
T: fmt::Debug,
F: FnMut(&T) -> bool,
A: Allocator + Clone,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ExtractIf").field(&self.inner.peek().map(|(k, _)| k)).finish()
f.debug_struct("ExtractIf")
.field("peek", &self.inner.peek().map(|(k, _)| k))
.finish_non_exhaustive()
}
}
+7 -2
View File
@@ -1976,9 +1976,14 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
#[stable(feature = "extract_if", since = "1.87.0")]
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
where
T: fmt::Debug,
A: Allocator,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ExtractIf").field(&self.list).finish()
let peek = self.it.map(|node| unsafe { &node.as_ref().element });
f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive()
}
}
+13 -2
View File
@@ -1,5 +1,5 @@
use core::ops::{Range, RangeBounds};
use core::{ptr, slice};
use core::{fmt, ptr, slice};
use super::Vec;
use crate::alloc::{Allocator, Global};
@@ -16,7 +16,6 @@
/// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(.., |x| *x % 2 == 0);
/// ```
#[stable(feature = "extract_if", since = "1.87.0")]
#[derive(Debug)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ExtractIf<
'a,
@@ -108,3 +107,15 @@ fn drop(&mut self) {
}
}
}
#[stable(feature = "extract_if", since = "1.87.0")]
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
where
T: fmt::Debug,
A: Allocator,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let peek = if self.idx < self.end { self.vec.get(self.idx) } else { None };
f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive()
}
}
+9 -11
View File
@@ -683,7 +683,7 @@ pub fn drain(&mut self) -> Drain<'_, K, V> {
/// ```
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
@@ -1680,12 +1680,9 @@ pub(super) fn iter(&self) -> Iter<'_, K, V> {
/// ]);
/// let iter = map.extract_if(|_k, v| *v % 2 == 0);
/// ```
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ExtractIf<'a, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
{
pub struct ExtractIf<'a, K, V, F> {
base: base::ExtractIf<'a, K, V, F>,
}
@@ -2297,7 +2294,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, V, F> Iterator for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
@@ -2314,13 +2311,14 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F>
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, V, F> fmt::Debug for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExtractIf").finish_non_exhaustive()
+8 -11
View File
@@ -308,7 +308,7 @@ pub fn drain(&mut self) -> Drain<'_, T> {
/// ```
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, T, F>
where
F: FnMut(&T) -> bool,
@@ -1390,11 +1390,8 @@ pub struct Drain<'a, K: 'a> {
///
/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0);
/// ```
#[stable(feature = "hash_extract_if", since = "1.87.0")]
pub struct ExtractIf<'a, K, F>
where
F: FnMut(&K) -> bool,
{
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub struct ExtractIf<'a, K, F> {
base: base::ExtractIf<'a, K, F>,
}
@@ -1673,7 +1670,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, F> Iterator for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool,
@@ -1690,13 +1687,13 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, F> FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {}
#[stable(feature = "hash_extract_if", since = "1.87.0")]
impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F>
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, F> fmt::Debug for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool,
K: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExtractIf").finish_non_exhaustive()
+1 -1
View File
@@ -13,9 +13,9 @@ const EXPECTED = [
{ 'path': 'std::vec', 'name': 'IntoIter' },
{ 'path': 'std::vec::Vec', 'name': 'from_iter' },
{ 'path': 'std::vec::Vec', 'name': 'into_iter' },
{ 'path': 'std::vec::ExtractIf', 'name': 'into_iter' },
{ 'path': 'std::vec::Drain', 'name': 'into_iter' },
{ 'path': 'std::vec::IntoIter', 'name': 'into_iter' },
{ 'path': 'std::vec::ExtractIf', 'name': 'into_iter' },
{ 'path': 'std::vec::Splice', 'name': 'into_iter' },
{ 'path': 'std::collections::VecDeque', 'name': 'iter' },
{ 'path': 'std::collections::VecDeque', 'name': 'iter_mut' },