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> {
821
821
}
822
822
}
823
823
824
- /// If the SmallVec has not spilled onto the heap, convert it into an `A`. Otherwise return `Err(Self)`.
825
824
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 ( ) {
827
830
Err ( self )
828
831
} else {
829
832
unsafe {
@@ -1972,6 +1975,9 @@ mod tests {
1972
1975
let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..2 ) ;
1973
1976
assert_eq ! ( vec. into_inner( ) , Ok ( [ 0 , 1 ] ) ) ;
1974
1977
1978
+ let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..1 ) ;
1979
+ assert_eq ! ( vec. clone( ) . into_inner( ) , Err ( vec) ) ;
1980
+
1975
1981
let vec = SmallVec :: < [ u8 ; 2 ] > :: from_iter ( 0 ..3 ) ;
1976
1982
assert_eq ! ( vec. clone( ) . into_inner( ) , Err ( vec) ) ;
1977
1983
}
You can’t perform that action at this time.
0 commit comments