about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-06-04 21:31:19 +0200
committerGitHub <noreply@github.com>2020-06-04 21:31:19 +0200
commite324c25fff9b6a348ebe4ffd86f20326dc4cda1d (patch)
treeb200b279ceb6ce68df70e3ac4abc286e4ce492b5
parentb584687f4f8fb209ceb85134a7f97b414a0f8e5d (diff)
parent29ab6b73e17af465bd9d25a6b59124f62c19f9f6 (diff)
downloadrust-e324c25fff9b6a348ebe4ffd86f20326dc4cda1d.tar.gz
rust-e324c25fff9b6a348ebe4ffd86f20326dc4cda1d.zip
Rollup merge of #72986 - pickfire:vec-assert, r=Mark-Simulacrum
Add more assert to Vec with_capacity docs

Show assertion on len too to show them how adding new items will affect both the
length and capacity, before and after.
-rw-r--r--src/liballoc/vec.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 22d43468771..ffae3b5c789 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -343,15 +343,18 @@ impl<T> Vec<T> {
     ///
     /// // The vector contains no items, even though it has capacity for more
     /// assert_eq!(vec.len(), 0);
+    /// assert_eq!(vec.capacity(), 10);
     ///
     /// // These are all done without reallocating...
     /// for i in 0..10 {
     ///     vec.push(i);
     /// }
+    /// assert_eq!(vec.len(), 10);
     /// assert_eq!(vec.capacity(), 10);
     ///
     /// // ...but this may make the vector reallocate
     /// vec.push(11);
+    /// assert_eq!(vec.len(), 11);
     /// assert!(vec.capacity() >= 11);
     /// ```
     #[inline]