Skip to content

Commit 4543ce5

Browse files
committed
Consistent trait bounds for ExtractIf Debug impls
1 parent 1bea580 commit 4543ce5

File tree

8 files changed

+59
-57
lines changed

8 files changed

+59
-57
lines changed

library/Cargo.lock

+2-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"
@@ -134,11 +128,10 @@ dependencies = [
134128

135129
[[package]]
136130
name = "hashbrown"
137-
version = "0.15.2"
131+
version = "0.15.3"
138132
source = "registry+https://github.com/rust-lang/crates.io-index"
139-
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
133+
checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
140134
dependencies = [
141-
"allocator-api2",
142135
"compiler_builtins",
143136
"rustc-std-workspace-alloc",
144137
"rustc-std-workspace-core",

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
11511151
/// assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
11521152
/// assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 9, 11, 13, 15]);
11531153
/// ```
1154-
#[stable(feature = "extract_if", since = "1.87.0")]
1154+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
11551155
pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A>
11561156
where
11571157
F: FnMut(&mut T) -> bool,
@@ -1931,7 +1931,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
19311931
}
19321932

19331933
/// An iterator produced by calling `extract_if` on LinkedList.
1934-
#[stable(feature = "extract_if", since = "1.87.0")]
1934+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
19351935
#[must_use = "iterators are lazy and do nothing unless consumed"]
19361936
pub struct ExtractIf<
19371937
'a,
@@ -1946,7 +1946,7 @@ pub struct ExtractIf<
19461946
old_len: usize,
19471947
}
19481948

1949-
#[stable(feature = "extract_if", since = "1.87.0")]
1949+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
19501950
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
19511951
where
19521952
F: FnMut(&mut T) -> bool,
@@ -1975,10 +1975,15 @@ where
19751975
}
19761976
}
19771977

1978-
#[stable(feature = "extract_if", since = "1.87.0")]
1979-
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
1978+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
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

+16-5
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};
@@ -15,8 +15,7 @@ use crate::alloc::{Allocator, Global};
1515
/// let mut v = vec![0, 1, 2];
1616
/// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(.., |x| *x % 2 == 0);
1717
/// ```
18-
#[stable(feature = "extract_if", since = "1.87.0")]
19-
#[derive(Debug)]
18+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
2019
#[must_use = "iterators are lazy and do nothing unless consumed"]
2120
pub struct ExtractIf<
2221
'a,
@@ -57,7 +56,7 @@ impl<'a, T, F, A: Allocator> ExtractIf<'a, T, F, A> {
5756
}
5857
}
5958

60-
#[stable(feature = "extract_if", since = "1.87.0")]
59+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
6160
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
6261
where
6362
F: FnMut(&mut T) -> bool,
@@ -93,7 +92,7 @@ where
9392
}
9493
}
9594

96-
#[stable(feature = "extract_if", since = "1.87.0")]
95+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
9796
impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
9897
fn drop(&mut self) {
9998
unsafe {
@@ -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 = "CURRENT_RUSTC_VERSION")]
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/alloc/src/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use core::ptr::{self, NonNull};
6666
use core::slice::{self, SliceIndex};
6767
use core::{fmt, intrinsics};
6868

69-
#[stable(feature = "extract_if", since = "1.87.0")]
69+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
7070
pub use self::extract_if::ExtractIf;
7171
use crate::alloc::{Allocator, Global};
7272
use crate::borrow::{Cow, ToOwned};
@@ -3715,7 +3715,7 @@ impl<T, A: Allocator> Vec<T, A> {
37153715
/// assert_eq!(items, vec![0, 0, 0, 0, 0, 0, 0, 2, 2, 2]);
37163716
/// assert_eq!(ones.len(), 3);
37173717
/// ```
3718-
#[stable(feature = "extract_if", since = "1.87.0")]
3718+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
37193719
pub fn extract_if<F, R>(&mut self, range: R, filter: F) -> ExtractIf<'_, T, F, A>
37203720
where
37213721
F: FnMut(&mut T) -> bool,

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl<K, V, S> HashMap<K, V, S> {
683683
/// ```
684684
#[inline]
685685
#[rustc_lint_query_instability]
686-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
686+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
687687
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
688688
where
689689
F: FnMut(&K, &mut V) -> bool,
@@ -1680,12 +1680,9 @@ impl<'a, K, V> Drain<'a, K, V> {
16801680
/// ]);
16811681
/// let iter = map.extract_if(|_k, v| *v % 2 == 0);
16821682
/// ```
1683-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1683+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
16841684
#[must_use = "iterators are lazy and do nothing unless consumed"]
1685-
pub struct ExtractIf<'a, K, V, F>
1686-
where
1687-
F: FnMut(&K, &mut V) -> bool,
1688-
{
1685+
pub struct ExtractIf<'a, K, V, F> {
16891686
base: base::ExtractIf<'a, K, V, F>,
16901687
}
16911688

@@ -2297,7 +2294,7 @@ where
22972294
}
22982295
}
22992296

2300-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
2297+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
23012298
impl<K, V, F> Iterator for ExtractIf<'_, K, V, F>
23022299
where
23032300
F: FnMut(&K, &mut V) -> bool,
@@ -2314,13 +2311,14 @@ where
23142311
}
23152312
}
23162313

2317-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
2314+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
23182315
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
23192316

2320-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
2321-
impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F>
2317+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
2318+
impl<K, V, F> fmt::Debug for ExtractIf<'_, K, V, F>
23222319
where
2323-
F: FnMut(&K, &mut V) -> bool,
2320+
K: fmt::Debug,
2321+
V: fmt::Debug,
23242322
{
23252323
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23262324
f.debug_struct("ExtractIf").finish_non_exhaustive()

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<T, S> HashSet<T, S> {
308308
/// ```
309309
#[inline]
310310
#[rustc_lint_query_instability]
311-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
311+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
312312
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, T, F>
313313
where
314314
F: FnMut(&T) -> bool,
@@ -1390,11 +1390,8 @@ pub struct Drain<'a, K: 'a> {
13901390
///
13911391
/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0);
13921392
/// ```
1393-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1394-
pub struct ExtractIf<'a, K, F>
1395-
where
1396-
F: FnMut(&K) -> bool,
1397-
{
1393+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
1394+
pub struct ExtractIf<'a, K, F> {
13981395
base: base::ExtractIf<'a, K, F>,
13991396
}
14001397

@@ -1673,7 +1670,7 @@ impl<K: fmt::Debug> fmt::Debug for Drain<'_, K> {
16731670
}
16741671
}
16751672

1676-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1673+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
16771674
impl<K, F> Iterator for ExtractIf<'_, K, F>
16781675
where
16791676
F: FnMut(&K) -> bool,
@@ -1690,13 +1687,13 @@ where
16901687
}
16911688
}
16921689

1693-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1690+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
16941691
impl<K, F> FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {}
16951692

1696-
#[stable(feature = "hash_extract_if", since = "1.87.0")]
1697-
impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F>
1693+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
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)