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 @@ -2626,13 +2626,21 @@ impl<T: Clone> Clone for IntoIter<T> {
26262626#[ stable( feature = "rust1" , since = "1.0.0" ) ]
26272627unsafe impl < #[ may_dangle] T > Drop for IntoIter < T > {
26282628 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 ) ;
26292639 // destroy the remaining elements
26302640 unsafe {
2631- ptr:: drop_in_place ( self . as_mut_slice ( ) ) ;
2641+ ptr:: drop_in_place ( guard . 0 . as_mut_slice ( ) ) ;
26322642 }
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
26362644 }
26372645}
26382646
You can’t perform that action at this time.
0 commit comments