Rollup merge of #44534 - adlerd:drain_filter_doctest, r=bluss

Fix drain_filter doctest.

Fixes #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.
This commit is contained in:
Corey Farwell 2017-09-14 22:32:46 -04:00 committed by GitHub
commit a48cc80d57

View File

@ -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,