File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -2086,6 +2086,12 @@ fn from_into_iter_source<T, I>(mut iterator: I) -> Vec<T>
2086
2086
where
2087
2087
I : Iterator < Item = T > + InPlaceIterable + SourceIter < Source = IntoIter < T > > ,
2088
2088
{
2089
+ // This specialization only makes sense if we're juggling real allocations.
2090
+ // Additionally some of the pointer arithmetic would panic on ZSTs.
2091
+ if mem:: size_of :: < T > ( ) == 0 {
2092
+ return SpecFromNested :: from_iter ( iterator) ;
2093
+ }
2094
+
2089
2095
let src_buf = iterator. as_inner ( ) . buf . as_ptr ( ) ;
2090
2096
let src_end = iterator. as_inner ( ) . end ;
2091
2097
let dst = src_buf;
@@ -2132,6 +2138,13 @@ where
2132
2138
debug_assert_eq ! ( src_buf, src. buf. as_ptr( ) ) ;
2133
2139
debug_assert ! ( dst as * const _ <= src. ptr, "InPlaceIterable contract violation" ) ;
2134
2140
2141
+ if mem:: needs_drop :: < T > ( ) {
2142
+ // drop tail if iterator was only partially exhaused
2143
+ unsafe {
2144
+ ptr:: drop_in_place ( src. as_mut_slice ( ) ) ;
2145
+ }
2146
+ }
2147
+
2135
2148
let vec = unsafe {
2136
2149
let len = dst. offset_from ( src_buf) as usize ;
2137
2150
Vec :: from_raw_parts ( src. buf . as_ptr ( ) , len, src. cap )
You can’t perform that action at this time.
0 commit comments