File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -2626,13 +2626,21 @@ impl<T: Clone> Clone for IntoIter<T> {
2626
2626
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2627
2627
unsafe impl < #[ may_dangle] T > Drop for IntoIter < T > {
2628
2628
fn drop ( & mut self ) {
2629
+ struct DropGuard < ' a , T > ( & ' a mut IntoIter < T > ) ;
2630
+
2631
+ impl < T > Drop for DropGuard < ' _ , T > {
2632
+ fn drop ( & mut self ) {
2633
+ // RawVec handles deallocation
2634
+ let _ = unsafe { RawVec :: from_raw_parts ( self . 0 . buf . as_ptr ( ) , self . 0 . cap ) } ;
2635
+ }
2636
+ }
2637
+
2638
+ let guard = DropGuard ( self ) ;
2629
2639
// destroy the remaining elements
2630
2640
unsafe {
2631
- ptr:: drop_in_place ( self . as_mut_slice ( ) ) ;
2641
+ ptr:: drop_in_place ( guard . 0 . as_mut_slice ( ) ) ;
2632
2642
}
2633
-
2634
- // RawVec handles deallocation
2635
- let _ = unsafe { RawVec :: from_raw_parts ( self . buf . as_ptr ( ) , self . cap ) } ;
2643
+ // now `guard` will be dropped and do the rest
2636
2644
}
2637
2645
}
2638
2646
You can’t perform that action at this time.
0 commit comments