about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-09-14 22:32:46 -0400
committerGitHub <noreply@github.com>2017-09-14 22:32:46 -0400
commita48cc80d5711412e1c1aecafebd51f9b485965f1 (patch)
tree7be75aca8c045f3aed16770b9da0c890d1efe8e2 /src/liballoc
parent50240f80f15bfce48aea1c270009936646a9f83e (diff)
parent518bd3085413670d3f7ccbc77abb64a0cb4a198a (diff)
downloadrust-a48cc80d5711412e1c1aecafebd51f9b485965f1.tar.gz
rust-a48cc80d5711412e1c1aecafebd51f9b485965f1.zip
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.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 8141851b8c9..caca4010156 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -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,