diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-07-07 03:26:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-07 03:26:08 +0200 |
| commit | 02da29496566772c0e8d2a7c6b771503a13f5d7d (patch) | |
| tree | 9f0e87de07fb818567d99c37aefe38c23966138c | |
| parent | a1b51aa4003354ab4cb129f1ec9c4e4d45ddf803 (diff) | |
| parent | 39575d39c5663af91c327fe33f9459e312d96ae0 (diff) | |
| download | rust-02da29496566772c0e8d2a7c6b771503a13f5d7d.tar.gz rust-02da29496566772c0e8d2a7c6b771503a13f5d7d.zip | |
Rollup merge of #143529 - pixel27:master, r=jhpratt
Renamed retain_mut to retain on LinkedList as mentioned in the ACP This is for proposal: https://github.com/rust-lang/libs-team/issues/250 The original check-in (https://github.com/rust-lang/rust/pull/114136) contained both methods **retain** and **retain_mut**, which does not conform to https://github.com/rust-lang/libs-team/issues/250#issuecomment-1766822671. 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.
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index d03c1969b5b..70c344e49b7 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1031,7 +1031,7 @@ impl<T, A: Allocator> LinkedList<T, A> { /// Retains only the elements specified by the predicate. /// - /// In other words, remove all elements `e` for which `f(&e)` returns false. + /// In other words, remove all elements `e` for which `f(&mut e)` returns false. /// This method operates in place, visiting each element exactly once in the /// original order, and preserves the order of the retained elements. /// @@ -1047,7 +1047,7 @@ impl<T, A: Allocator> LinkedList<T, A> { /// d.push_front(2); /// d.push_front(3); /// - /// d.retain(|&x| x % 2 == 0); + /// d.retain(|&mut x| x % 2 == 0); /// /// assert_eq!(d.pop_front(), Some(2)); /// assert_eq!(d.pop_front(), None); @@ -1075,41 +1075,6 @@ impl<T, A: Allocator> LinkedList<T, A> { #[unstable(feature = "linked_list_retain", issue = "114135")] pub fn retain<F>(&mut self, mut f: F) where - F: FnMut(&T) -> bool, - { - self.retain_mut(|elem| f(elem)); - } - - /// Retains only the elements specified by the predicate. - /// - /// In other words, remove all elements `e` for which `f(&mut e)` returns false. - /// This method operates in place, visiting each element exactly once in the - /// original order, and preserves the order of the retained elements. - /// - /// # Examples - /// - /// ``` - /// #![feature(linked_list_retain)] - /// use std::collections::LinkedList; - /// - /// let mut d = LinkedList::new(); - /// - /// d.push_front(1); - /// d.push_front(2); - /// d.push_front(3); - /// - /// d.retain_mut(|x| if *x % 2 == 0 { - /// *x += 1; - /// true - /// } else { - /// false - /// }); - /// assert_eq!(d.pop_front(), Some(3)); - /// assert_eq!(d.pop_front(), None); - /// ``` - #[unstable(feature = "linked_list_retain", issue = "114135")] - pub fn retain_mut<F>(&mut self, mut f: F) - where F: FnMut(&mut T) -> bool, { let mut cursor = self.cursor_front_mut(); |
