Skip to content

Commit 02da294

Browse files
authored
Rollup merge of #143529 - pixel27:master, r=jhpratt
Renamed retain_mut to retain on LinkedList as mentioned in the ACP This is for proposal: rust-lang/libs-team#250 The original check-in (#114136) contained both methods **retain** and **retain_mut**, which does not conform to rust-lang/libs-team#250 (comment). I updated the retain documentation to specify **&mut e**, removed the **retain** method and renamed **retain_mut** to **retain** to conform to the request. The pull request doesn't really contain much that is new, just removes the unwanted method to meet the requirements. I've run the tests "library/alloc" on the code and no issues. Hopefully I'm not stepping on the original author's toes. I just ran across a need for the method and wondered why it was unstable.
2 parents a1b51aa + 39575d3 commit 02da294

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

library/alloc/src/collections/linked_list.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
10311031

10321032
/// Retains only the elements specified by the predicate.
10331033
///
1034-
/// In other words, remove all elements `e` for which `f(&e)` returns false.
1034+
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
10351035
/// This method operates in place, visiting each element exactly once in the
10361036
/// original order, and preserves the order of the retained elements.
10371037
///
@@ -1047,7 +1047,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
10471047
/// d.push_front(2);
10481048
/// d.push_front(3);
10491049
///
1050-
/// d.retain(|&x| x % 2 == 0);
1050+
/// d.retain(|&mut x| x % 2 == 0);
10511051
///
10521052
/// assert_eq!(d.pop_front(), Some(2));
10531053
/// assert_eq!(d.pop_front(), None);
@@ -1074,41 +1074,6 @@ impl<T, A: Allocator> LinkedList<T, A> {
10741074
/// ```
10751075
#[unstable(feature = "linked_list_retain", issue = "114135")]
10761076
pub fn retain<F>(&mut self, mut f: F)
1077-
where
1078-
F: FnMut(&T) -> bool,
1079-
{
1080-
self.retain_mut(|elem| f(elem));
1081-
}
1082-
1083-
/// Retains only the elements specified by the predicate.
1084-
///
1085-
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
1086-
/// This method operates in place, visiting each element exactly once in the
1087-
/// original order, and preserves the order of the retained elements.
1088-
///
1089-
/// # Examples
1090-
///
1091-
/// ```
1092-
/// #![feature(linked_list_retain)]
1093-
/// use std::collections::LinkedList;
1094-
///
1095-
/// let mut d = LinkedList::new();
1096-
///
1097-
/// d.push_front(1);
1098-
/// d.push_front(2);
1099-
/// d.push_front(3);
1100-
///
1101-
/// d.retain_mut(|x| if *x % 2 == 0 {
1102-
/// *x += 1;
1103-
/// true
1104-
/// } else {
1105-
/// false
1106-
/// });
1107-
/// assert_eq!(d.pop_front(), Some(3));
1108-
/// assert_eq!(d.pop_front(), None);
1109-
/// ```
1110-
#[unstable(feature = "linked_list_retain", issue = "114135")]
1111-
pub fn retain_mut<F>(&mut self, mut f: F)
11121077
where
11131078
F: FnMut(&mut T) -> bool,
11141079
{

0 commit comments

Comments
 (0)