about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-14 20:31:59 +0100
committerGitHub <noreply@github.com>2019-01-14 20:31:59 +0100
commit8a62e393b8fba95e989020f2efbf846ca02113f9 (patch)
tree2aa2f0658dadf106b332587148395d9b3087faac /src/liballoc/vec.rs
parentb03d414e3c222a7f29259526fcdf95189e61fd0c (diff)
parent1fd971c3b97bc1f01740a552aeb3d23b6ed194f5 (diff)
downloadrust-8a62e393b8fba95e989020f2efbf846ca02113f9.tar.gz
rust-8a62e393b8fba95e989020f2efbf846ca02113f9.zip
Rollup merge of #57589 - scottmcm:vec-set_len-debug_assert, r=alexcrichton
Add a debug_assert to Vec::set_len

Following the precedent of https://github.com/rust-lang/rust/pull/52972, which found https://github.com/llogiq/bytecount/pull/42.

(This may well make a test fail; let's see what Travis says.)
Diffstat (limited to 'src/liballoc/vec.rs')
-rw-r--r--src/liballoc/vec.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index e1c5ab15bb5..ba3b3dfbfc2 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -819,6 +819,8 @@ impl<T> Vec<T> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub unsafe fn set_len(&mut self, new_len: usize) {
+        debug_assert!(new_len <= self.capacity());
+
         self.len = new_len;
     }