about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-02-13 16:36:52 +0900
committerGitHub <noreply@github.com>2021-02-13 16:36:52 +0900
commit0ca5fd7ebcbe57a6f9dcd84a3aef50278bc33628 (patch)
treebe763236b7a1c2aa252500531250ed1a329a0939
parent2673026995ee902f934cc2fc83045bc87cb14e32 (diff)
parentfa9af6a9be72e80c7c86adf656bee5964cb2f6a2 (diff)
downloadrust-0ca5fd7ebcbe57a6f9dcd84a3aef50278bc33628.tar.gz
rust-0ca5fd7ebcbe57a6f9dcd84a3aef50278bc33628.zip
Rollup merge of #82050 - hbina:fix/added-test-to-drain-empty-vec, r=dtolnay
Added tests to drain an empty vec

Discovered this kind of issue in an unrelated library.
The author copied the tests from here and AFAIK, there are no tests for this particular case.

https://github.com/LeonineKing1199/minivec/pull/19

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
-rw-r--r--library/alloc/tests/vec.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs
index e3d74791dcf..2969da58d42 100644
--- a/library/alloc/tests/vec.rs
+++ b/library/alloc/tests/vec.rs
@@ -610,6 +610,17 @@ fn test_move_items_zero_sized() {
 }
 
 #[test]
+fn test_drain_empty_vec() {
+    let mut vec: Vec<i32> = vec![];
+    let mut vec2: Vec<i32> = vec![];
+    for i in vec.drain(..) {
+        vec2.push(i);
+    }
+    assert!(vec.is_empty());
+    assert!(vec2.is_empty());
+}
+
+#[test]
 fn test_drain_items() {
     let mut vec = vec![1, 2, 3];
     let mut vec2 = vec![];