File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -565,6 +565,41 @@ fn drain_filter_drop_panic_leak() {
565565 assert ! ( q. is_empty( ) ) ;
566566}
567567
568+ #[ test]
569+ fn drain_filter_pred_panic_leak ( ) {
570+ static mut DROPS : i32 = 0 ;
571+
572+ #[ derive( Debug ) ]
573+ struct D ( u32 ) ;
574+
575+ impl Drop for D {
576+ fn drop ( & mut self ) {
577+ unsafe {
578+ DROPS += 1 ;
579+ }
580+ }
581+ }
582+
583+ let mut q = LinkedList :: new ( ) ;
584+ q. push_back ( D ( 3 ) ) ;
585+ q. push_back ( D ( 4 ) ) ;
586+ q. push_back ( D ( 5 ) ) ;
587+ q. push_back ( D ( 6 ) ) ;
588+ q. push_back ( D ( 7 ) ) ;
589+ q. push_front ( D ( 2 ) ) ;
590+ q. push_front ( D ( 1 ) ) ;
591+ q. push_front ( D ( 0 ) ) ;
592+
593+ catch_unwind ( AssertUnwindSafe ( || drop ( q. drain_filter ( |item| if item. 0 >= 2 {
594+ panic ! ( )
595+ } else {
596+ true
597+ } ) ) ) ) . ok ( ) ;
598+
599+ assert_eq ! ( unsafe { DROPS } , 2 ) ; // 0 and 1
600+ assert_eq ! ( q. len( ) , 6 ) ;
601+ }
602+
568603#[ test]
569604fn test_drop ( ) {
570605 static mut DROPS : i32 = 0 ;
You can’t perform that action at this time.
0 commit comments