Skip to content

Commit 0ca5fd7

Browse files
authored
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. cmazakas/minivec#19 Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2 parents 2673026 + fa9af6a commit 0ca5fd7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/alloc/tests/vec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,17 @@ fn test_move_items_zero_sized() {
609609
assert_eq!(vec2, [(), (), ()]);
610610
}
611611

612+
#[test]
613+
fn test_drain_empty_vec() {
614+
let mut vec: Vec<i32> = vec![];
615+
let mut vec2: Vec<i32> = vec![];
616+
for i in vec.drain(..) {
617+
vec2.push(i);
618+
}
619+
assert!(vec.is_empty());
620+
assert!(vec2.is_empty());
621+
}
622+
612623
#[test]
613624
fn test_drain_items() {
614625
let mut vec = vec![1, 2, 3];

0 commit comments

Comments
 (0)