This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,35 @@ fn test_into_iter_clone() {
765
765
assert_eq ! ( it. next( ) , None ) ;
766
766
}
767
767
768
+ #[ test]
769
+ fn test_into_iter_leak ( ) {
770
+ static mut DROPS : i32 = 0 ;
771
+
772
+ struct D ( bool ) ;
773
+
774
+ impl Drop for D {
775
+ fn drop ( & mut self ) {
776
+ unsafe {
777
+ DROPS += 1 ;
778
+ }
779
+
780
+ if self . 0 {
781
+ panic ! ( "panic in `drop`" ) ;
782
+ }
783
+ }
784
+ }
785
+
786
+ let v = vec ! [
787
+ D ( false ) ,
788
+ D ( true ) ,
789
+ D ( false ) ,
790
+ ] ;
791
+
792
+ catch_unwind ( move || drop ( v. into_iter ( ) ) ) . ok ( ) ;
793
+
794
+ assert_eq ! ( unsafe { DROPS } , 3 ) ;
795
+ }
796
+
768
797
#[ test]
769
798
fn test_cow_from ( ) {
770
799
let borrowed: & [ _ ] = & [ "borrowed" , "(slice)" ] ;
Original file line number Diff line number Diff line change @@ -2620,7 +2620,9 @@ impl<T: Clone> Clone for IntoIter<T> {
2620
2620
unsafe impl < #[ may_dangle] T > Drop for IntoIter < T > {
2621
2621
fn drop ( & mut self ) {
2622
2622
// destroy the remaining elements
2623
- for _x in self . by_ref ( ) { }
2623
+ unsafe {
2624
+ ptr:: drop_in_place ( self . as_mut_slice ( ) ) ;
2625
+ }
2624
2626
2625
2627
// RawVec handles deallocation
2626
2628
let _ = unsafe { RawVec :: from_raw_parts ( self . buf . as_ptr ( ) , self . cap ) } ;
You can’t perform that action at this time.
0 commit comments