Skip to content

Commit

Permalink
Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
schteve committed Feb 7, 2021
1 parent 23adf9f commit 0488afd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,13 +1385,14 @@ impl<T, A: Allocator> Vec<T, A> {
/// assert_eq!(vec, [2, 4]);
/// ```
///
/// The exact order may be useful for tracking external state, like an index.
/// Because the elements are visited exactly once in the original order,
/// external state may be used to decide which elements to keep.
///
/// ```
/// let mut vec = vec![1, 2, 3, 4, 5];
/// let keep = [false, true, true, false, true];
/// let mut i = 0;
/// vec.retain(|_| (keep[i], i += 1).0);
/// let mut iter = keep.iter();
/// vec.retain(|_| *iter.next().unwrap());
/// assert_eq!(vec, [2, 3, 5]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit 0488afd

Please sign in to comment.