File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -301,7 +301,11 @@ impl<A: Array> SmallVec<A> {
301
301
}
302
302
}
303
303
304
+ /// Re-allocate to set the capacity to `new_cap`.
305
+ ///
306
+ /// Panics if `new_cap` is less than the vector's length.
304
307
pub fn grow ( & mut self , new_cap : usize ) {
308
+ assert ! ( new_cap >= self . len) ;
305
309
let mut vec: Vec < A :: Item > = Vec :: with_capacity ( new_cap) ;
306
310
let new_alloc = vec. as_mut_ptr ( ) ;
307
311
unsafe {
@@ -967,6 +971,14 @@ pub mod tests {
967
971
assert_eq ! ( & v. iter( ) . map( |v| * * v) . collect:: <Vec <_>>( ) , & [ 0 , 3 , 2 ] ) ;
968
972
}
969
973
974
+ #[ test]
975
+ #[ should_panic]
976
+ fn test_invalid_grow ( ) {
977
+ let mut v: SmallVec < [ u8 ; 8 ] > = SmallVec :: new ( ) ;
978
+ v. extend ( 0 ..8 ) ;
979
+ v. grow ( 5 ) ;
980
+ }
981
+
970
982
#[ test]
971
983
#[ should_panic]
972
984
fn test_drop_panic_smallvec ( ) {
You can’t perform that action at this time.
0 commit comments