about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-14 11:27:12 +0200
committerGitHub <noreply@github.com>2025-06-14 11:27:12 +0200
commit22f91aefd5b0ec5d17f9dfe8f6e8ceb5af25c8b3 (patch)
treecb0b99d4f05c55816e20716f11c9491399b185fd /library/alloc/src
parent4bf7765388da436dc952ac7300ffc114cff37676 (diff)
parentdac9d78647f2a1483710e2417d817c7df04eba8d (diff)
downloadrust-22f91aefd5b0ec5d17f9dfe8f6e8ceb5af25c8b3.tar.gz
rust-22f91aefd5b0ec5d17f9dfe8f6e8ceb5af25c8b3.zip
Rollup merge of #142484 - dtolnay:bsetextract, r=m-ou-se
Remove unneeded lifetime bound from signature of BTreeSet::extract_if

One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses:

```rust
use std::collections::btree_set::{BTreeSet, ExtractIf};
use std::ops::RangeFull;

fn repro(
    set: &mut BTreeSet<i32>,
    predicate: impl Fn(i32) -> bool,
) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> {
    set.extract_if(.., move |x| predicate(*x))
}
```

**Before:**

```console
error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough
 --> src/lib.rs:8:5
  |
5 |     set: &mut BTreeSet<i32>,
  |          ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here...
...
8 |     set.extract_if(.., move |x| predicate(*x))
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound
  |
4 ~ fn repro<'a>(
5 ~     set: &'a mut BTreeSet<i32>,
6 ~     predicate: impl Fn(i32) -> bool + 'a,
7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> {
  |
```

**After:** compiles success.

- Tracking issue: https://github.com/rust-lang/rust/issues/70530
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/collections/btree/set.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs
index 51418036f42..aa9e5fce1d4 100644
--- a/library/alloc/src/collections/btree/set.rs
+++ b/library/alloc/src/collections/btree/set.rs
@@ -1220,11 +1220,11 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
     /// assert_eq!(high.into_iter().collect::<Vec<_>>(), [4, 5, 6, 7]);
     /// ```
     #[unstable(feature = "btree_extract_if", issue = "70530")]
-    pub fn extract_if<'a, F, R>(&'a mut self, range: R, pred: F) -> ExtractIf<'a, T, R, F, A>
+    pub fn extract_if<F, R>(&mut self, range: R, pred: F) -> ExtractIf<'_, T, R, F, A>
     where
         T: Ord,
         R: RangeBounds<T>,
-        F: 'a + FnMut(&T) -> bool,
+        F: FnMut(&T) -> bool,
     {
         let (inner, alloc) = self.map.extract_if_inner(range);
         ExtractIf { pred, inner, alloc }
@@ -1585,11 +1585,11 @@ where
 }
 
 #[unstable(feature = "btree_extract_if", issue = "70530")]
-impl<'a, T, R, F, A: Allocator + Clone> Iterator for ExtractIf<'_, T, R, F, A>
+impl<T, R, F, A: Allocator + Clone> Iterator for ExtractIf<'_, T, R, F, A>
 where
     T: PartialOrd,
     R: RangeBounds<T>,
-    F: 'a + FnMut(&T) -> bool,
+    F: FnMut(&T) -> bool,
 {
     type Item = T;