Skip to content

Commit b344e14

Browse files
authored
Rollup merge of #135956 - GrigorenkoPV:vec_pop_off, r=dtolnay
Make `Vec::pop_if` a bit more presentable #135488 minus stabilization. As suggested in #135488 (comment). r? tgross35
2 parents c459b17 + b2ad126 commit b344e14

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Diff for: library/alloc/src/vec/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -2511,9 +2511,9 @@ impl<T, A: Allocator> Vec<T, A> {
25112511
}
25122512
}
25132513

2514-
/// Removes and returns the last element in a vector if the predicate
2514+
/// Removes and returns the last element from a vector if the predicate
25152515
/// returns `true`, or [`None`] if the predicate returns false or the vector
2516-
/// is empty.
2516+
/// is empty (the predicate will not be called in that case).
25172517
///
25182518
/// # Examples
25192519
///
@@ -2528,12 +2528,9 @@ impl<T, A: Allocator> Vec<T, A> {
25282528
/// assert_eq!(vec.pop_if(pred), None);
25292529
/// ```
25302530
#[unstable(feature = "vec_pop_if", issue = "122741")]
2531-
pub fn pop_if<F>(&mut self, f: F) -> Option<T>
2532-
where
2533-
F: FnOnce(&mut T) -> bool,
2534-
{
2531+
pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T> {
25352532
let last = self.last_mut()?;
2536-
if f(last) { self.pop() } else { None }
2533+
if predicate(last) { self.pop() } else { None }
25372534
}
25382535

25392536
/// Moves all the elements of `other` into `self`, leaving `other` empty.

0 commit comments

Comments
 (0)