File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 9292 mem:: transmute :: < & [ MaybeUninit < T > ] , & [ T ] > ( slice)
9393 }
9494 }
95+
96+ /// Returns a mutable slice of all elements that have not been yielded yet.
97+ fn as_mut_slice ( & mut self ) -> & mut [ T ] {
98+ // This transmute is safe, same as in `as_slice` above.
99+ let slice = & mut self . data [ self . alive . clone ( ) ] ;
100+ unsafe {
101+ mem:: transmute :: < & mut [ MaybeUninit < T > ] , & mut [ T ] > ( slice)
102+ }
103+ }
95104}
96105
97106
@@ -184,10 +193,9 @@ where
184193 [ T ; N ] : LengthAtMost32 ,
185194{
186195 fn drop ( & mut self ) {
187- // We simply drop each element via `for_each`. This should not incur
188- // any significant runtime overhead and avoids adding another `unsafe`
189- // block.
190- self . by_ref ( ) . for_each ( drop) ;
196+ unsafe {
197+ ptr:: drop_in_place ( self . as_mut_slice ( ) )
198+ }
191199 }
192200}
193201
You can’t perform that action at this time.
0 commit comments