Skip to content

Commit fa46792

Browse files
committed
Consistent trait bounds for ExtractIf Debug impls
1 parent 092a284 commit fa46792

File tree

8 files changed

+42
-38
lines changed

8 files changed

+42
-38
lines changed

library/Cargo.lock

+1-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ dependencies = [
3232
"core",
3333
]
3434

35-
[[package]]
36-
name = "allocator-api2"
37-
version = "0.2.21"
38-
source = "registry+https://github.com/rust-lang/crates.io-index"
39-
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
40-
4135
[[package]]
4236
name = "alloctests"
4337
version = "0.0.0"
@@ -135,10 +129,8 @@ dependencies = [
135129
[[package]]
136130
name = "hashbrown"
137131
version = "0.15.2"
138-
source = "registry+https://github.com/rust-lang/crates.io-index"
139-
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
132+
source = "git+https://github.com/rust-lang/hashbrown?rev=refs%2Fpull%2F616%2Fhead#82cd86cc31a8f3a753dda0178f12946485e5fbbb"
140133
dependencies = [
141-
"allocator-api2",
142134
"compiler_builtins",
143135
"rustc-std-workspace-alloc",
144136
"rustc-std-workspace-core",

library/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ rustc-demangle.opt-level = "s"
5050
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
5151
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
5252
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
53+
54+
# FIXME https://github.com/rust-lang/hashbrown/pull/616
55+
hashbrown = { git = "https://github.com/rust-lang/hashbrown", rev = "refs/pull/616/head" }

library/alloc/src/collections/btree/map.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1917,14 +1917,13 @@ pub struct ExtractIf<
19171917
V,
19181918
F,
19191919
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
1920-
> where
1921-
F: 'a + FnMut(&K, &mut V) -> bool,
1922-
{
1920+
> {
19231921
pred: F,
19241922
inner: ExtractIfInner<'a, K, V>,
19251923
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
19261924
alloc: A,
19271925
}
1926+
19281927
/// Most of the implementation of ExtractIf are generic over the type
19291928
/// of the predicate, thus also serving for BTreeSet::ExtractIf.
19301929
pub(super) struct ExtractIfInner<'a, K, V> {
@@ -1940,14 +1939,14 @@ pub(super) struct ExtractIfInner<'a, K, V> {
19401939
}
19411940

19421941
#[unstable(feature = "btree_extract_if", issue = "70530")]
1943-
impl<K, V, F> fmt::Debug for ExtractIf<'_, K, V, F>
1942+
impl<K, V, F, A> fmt::Debug for ExtractIf<'_, K, V, F, A>
19441943
where
19451944
K: fmt::Debug,
19461945
V: fmt::Debug,
1947-
F: FnMut(&K, &mut V) -> bool,
1946+
A: Allocator + Clone,
19481947
{
19491948
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1950-
f.debug_tuple("ExtractIf").field(&self.inner.peek()).finish()
1949+
f.debug_struct("ExtractIf").field("peek", &self.inner.peek()).finish_non_exhaustive()
19511950
}
19521951
}
19531952

library/alloc/src/collections/btree/set.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1556,24 +1556,23 @@ pub struct ExtractIf<
15561556
T,
15571557
F,
15581558
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
1559-
> where
1560-
T: 'a,
1561-
F: 'a + FnMut(&T) -> bool,
1562-
{
1559+
> {
15631560
pred: F,
15641561
inner: super::map::ExtractIfInner<'a, T, SetValZST>,
15651562
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
15661563
alloc: A,
15671564
}
15681565

15691566
#[unstable(feature = "btree_extract_if", issue = "70530")]
1570-
impl<T, F, A: Allocator + Clone> fmt::Debug for ExtractIf<'_, T, F, A>
1567+
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
15711568
where
15721569
T: fmt::Debug,
1573-
F: FnMut(&T) -> bool,
1570+
A: Allocator + Clone,
15741571
{
15751572
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1576-
f.debug_tuple("ExtractIf").field(&self.inner.peek().map(|(k, _)| k)).finish()
1573+
f.debug_struct("ExtractIf")
1574+
.field("peek", &self.inner.peek().map(|(k, _)| k))
1575+
.finish_non_exhaustive()
15771576
}
15781577
}
15791578

library/alloc/src/collections/linked_list.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1976,9 +1976,14 @@ where
19761976
}
19771977

19781978
#[stable(feature = "extract_if", since = "1.87.0")]
1979-
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
1979+
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
1980+
where
1981+
T: fmt::Debug,
1982+
A: Allocator,
1983+
{
19801984
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1981-
f.debug_tuple("ExtractIf").field(&self.list).finish()
1985+
let peek = self.it.map(|node| unsafe { &node.as_ref().element });
1986+
f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive()
19821987
}
19831988
}
19841989

library/alloc/src/vec/extract_if.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::ops::{Range, RangeBounds};
2-
use core::{ptr, slice};
2+
use core::{fmt, ptr, slice};
33

44
use super::Vec;
55
use crate::alloc::{Allocator, Global};
@@ -16,7 +16,6 @@ use crate::alloc::{Allocator, Global};
1616
/// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(.., |x| *x % 2 == 0);
1717
/// ```
1818
#[stable(feature = "extract_if", since = "1.87.0")]
19-
#[derive(Debug)]
2019
#[must_use = "iterators are lazy and do nothing unless consumed"]
2120
pub struct ExtractIf<
2221
'a,
@@ -108,3 +107,15 @@ impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
108107
}
109108
}
110109
}
110+
111+
#[stable(feature = "extract_if", since = "1.87.0")]
112+
impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A>
113+
where
114+
T: fmt::Debug,
115+
A: Allocator,
116+
{
117+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118+
let peek = if self.idx < self.end { self.vec.get(self.idx) } else { None };
119+
f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive()
120+
}
121+
}

library/std/src/collections/hash/map.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1679,10 +1679,7 @@ impl<'a, K, V> Drain<'a, K, V> {
16791679
/// ```
16801680
#[stable(feature = "hash_extract_if", since = "1.87.0")]
16811681
#[must_use = "iterators are lazy and do nothing unless consumed"]
1682-
pub struct ExtractIf<'a, K, V, F>
1683-
where
1684-
F: FnMut(&K, &mut V) -> bool,
1685-
{
1682+
pub struct ExtractIf<'a, K, V, F> {
16861683
base: base::ExtractIf<'a, K, V, F>,
16871684
}
16881685

@@ -2315,9 +2312,10 @@ where
23152312
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
23162313

23172314
#[stable(feature = "hash_extract_if", since = "1.87.0")]
2318-
impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F>
2315+
impl<K, V, F> fmt::Debug for ExtractIf<'_, K, V, F>
23192316
where
2320-
F: FnMut(&K, &mut V) -> bool,
2317+
K: fmt::Debug,
2318+
V: fmt::Debug,
23212319
{
23222320
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23232321
f.debug_struct("ExtractIf").finish_non_exhaustive()

library/std/src/collections/hash/set.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,7 @@ pub struct Drain<'a, K: 'a> {
13911391
/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0);
13921392
/// ```
13931393
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1394-
pub struct ExtractIf<'a, K, F>
1395-
where
1396-
F: FnMut(&K) -> bool,
1397-
{
1394+
pub struct ExtractIf<'a, K, F> {
13981395
base: base::ExtractIf<'a, K, F>,
13991396
}
14001397

@@ -1694,9 +1691,9 @@ where
16941691
impl<K, F> FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {}
16951692

16961693
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1697-
impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F>
1694+
impl<K, F> fmt::Debug for ExtractIf<'_, K, F>
16981695
where
1699-
F: FnMut(&K) -> bool,
1696+
K: fmt::Debug,
17001697
{
17011698
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17021699
f.debug_struct("ExtractIf").finish_non_exhaustive()

0 commit comments

Comments
 (0)