Skip to content

Commit

Permalink
Rollup merge of rust-lang#44534 - adlerd:drain_filter_doctest, r=bluss
Browse files Browse the repository at this point in the history
Fix drain_filter doctest.

Fixes rust-lang#44499.

Also change some of the hidden logic in the doctest as a regression test; two bugs in the original would now cause test failure.
  • Loading branch information
frewsxcv authored Sep 14, 2017
2 parents 8ca0212 + 518bd30 commit 66c1954
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,16 +1969,19 @@ impl<T> Vec<T> {
/// Using this method is equivalent to the following code:
///
/// ```
/// # let some_predicate = |x: &mut i32| { *x == 2 };
/// # let mut vec = vec![1, 2, 3, 4, 5];
/// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 };
/// # let mut vec = vec![1, 2, 3, 4, 5, 6];
/// let mut i = 0;
/// while i != vec.len() {
/// if some_predicate(&mut vec[i]) {
/// let val = vec.remove(i);
/// // your code here
/// } else {
/// i += 1;
/// }
/// i += 1;
/// }
///
/// # assert_eq!(vec, vec![1, 4, 5]);
/// ```
///
/// But `drain_filter` is easier to use. `drain_filter` is also more efficient,
Expand Down

0 comments on commit 66c1954

Please sign in to comment.