about summary refs log tree commit diff
path: root/src/libcollections/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-04-20 13:08:07 +0000
committerbors <bors@rust-lang.org>2017-04-20 13:08:07 +0000
commit968ae7babecfc6c62ef9699ff052d9ab00411848 (patch)
tree8047c62010017e7f69253113832daef38777176c /src/libcollections/tests
parentfa6b50fc6282a2c64814b35b16464a22f4ae9265 (diff)
parentf85a5337ab0f8b492cb8df56a7c2af103010037e (diff)
downloadrust-968ae7babecfc6c62ef9699ff052d9ab00411848.tar.gz
rust-968ae7babecfc6c62ef9699ff052d9ab00411848.zip
Auto merge of #41191 - seanmonstar:spec-extend-vec-intoiter, r=alexcrichton
specialize Extend for Vec with IntoIter

Before, `vec.extend(&other_vec)` was quite a bit faster than `vec.extend(other_vec)`. This allows extending by consuming a vec to use the same code as extending from a slice.
Diffstat (limited to 'src/libcollections/tests')
-rw-r--r--src/libcollections/tests/vec.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libcollections/tests/vec.rs b/src/libcollections/tests/vec.rs
index 63df0eb7305..64c76142b59 100644
--- a/src/libcollections/tests/vec.rs
+++ b/src/libcollections/tests/vec.rs
@@ -84,6 +84,9 @@ fn test_extend() {
     let mut v = Vec::new();
     let mut w = Vec::new();
 
+    v.extend(w.clone());
+    assert_eq!(v, &[]);
+
     v.extend(0..3);
     for i in 0..3 {
         w.push(i)
@@ -100,6 +103,25 @@ fn test_extend() {
 
     v.extend(w.clone()); // specializes to `append`
     assert!(v.iter().eq(w.iter().chain(w.iter())));
+
+    // Zero sized types
+    #[derive(PartialEq, Debug)]
+    struct Foo;
+
+    let mut a = Vec::new();
+    let b = vec![Foo, Foo];
+
+    a.extend(b);
+    assert_eq!(a, &[Foo, Foo]);
+
+    // Double drop
+    let mut count_x = 0;
+    {
+        let mut x = Vec::new();
+        let y = vec![DropCounter { count: &mut count_x }];
+        x.extend(y);
+    }
+    assert_eq!(count_x, 1);
 }
 
 #[test]