From 1fd971c3b97bc1f01740a552aeb3d23b6ed194f5 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 14 Dec 2018 21:41:18 -0800 Subject: [PATCH] Add a debug_assert to Vec::set_len --- src/liballoc/vec.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index e1c5ab15bb5ce..ba3b3dfbfc2e1 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -819,6 +819,8 @@ impl Vec { #[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; }