File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -821,9 +821,12 @@ impl<A: Array> SmallVec<A> {
821821 }
822822 }
823823
824- /// If the SmallVec has not spilled onto the heap, convert it into an `A`. Otherwise return `Err(Self)`.
825824 pub fn into_inner ( mut self ) -> Result < A , Self > {
826- if self . spilled ( ) {
825+ /// Convert the SmallVec into an `A` if possible. Otherwise return `Err(Self)`.
826+ ///
827+ /// This method returns `Err(Self)` if the SmallVec is too short (and the `A` contains uninitialized elements),
828+ /// or if the SmallVec is too long (and all the elements were spilled to the heap).
829+ if self . spilled ( ) || self . len ( ) != A :: size ( ) {
827830 Err ( self )
828831 } else {
829832 unsafe {
@@ -1972,6 +1975,9 @@ mod tests {
19721975 let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..2 ) ;
19731976 assert_eq ! ( vec. into_inner( ) , Ok ( [ 0 , 1 ] ) ) ;
19741977
1978+ let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..1 ) ;
1979+ assert_eq ! ( vec. clone( ) . into_inner( ) , Err ( vec) ) ;
1980+
19751981 let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..3 ) ;
19761982 assert_eq ! ( vec. clone( ) . into_inner( ) , Err ( vec) ) ;
19771983 }
You can’t perform that action at this time.
0 commit comments