]> git.lizzy.rs Git - rust.git/blobdiff - src/libcollections/vec.rs
Rollup merge of #41249 - GuillaumeGomez:rustdoc-render, r=steveklabnik,frewsxcv
[rust.git] / src / libcollections / vec.rs
index c258ac2bdea9be0a81930b2d5bbb56cd1935c340..8824185d2809b1c5659fc2c7e98ebdcc898b6628 100644 (file)
@@ -1346,7 +1346,7 @@ pub fn dedup(&mut self) {
     /// # Examples
     ///
     /// ```
-    ///# #![feature(vec_remove_item)]
+    /// # #![feature(vec_remove_item)]
     /// let mut vec = vec![1, 2, 3, 1];
     ///
     /// vec.remove_item(&1);
@@ -1396,16 +1396,7 @@ fn clone(&self) -> Vec<T> {
     }
 
     fn clone_from(&mut self, other: &Vec<T>) {
-        // drop anything in self that will not be overwritten
-        self.truncate(other.len());
-        let len = self.len();
-
-        // reuse the contained values' allocations/resources.
-        self.clone_from_slice(&other[..len]);
-
-        // self.len <= other.len due to the truncate above, so the
-        // slice here is always in-bounds.
-        self.extend_from_slice(&other[len..]);
+        other.as_slice().clone_into(self);
     }
 }