File tree 1 file changed +37
-1
lines changed
1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -1027,7 +1027,7 @@ fn test_from_iter_specialization_head_tail_drop() {
1027
1027
}
1028
1028
1029
1029
#[ test]
1030
- fn test_from_iter_specialization_panic_drop ( ) {
1030
+ fn test_from_iter_specialization_panic_during_iteration_drops ( ) {
1031
1031
let drop_count: Vec < _ > = ( 0 ..=2 ) . map ( |_| Rc :: new ( ( ) ) ) . collect ( ) ;
1032
1032
let src: Vec < _ > = drop_count. iter ( ) . cloned ( ) . collect ( ) ;
1033
1033
let iter = src. into_iter ( ) ;
@@ -1050,6 +1050,42 @@ fn test_from_iter_specialization_panic_drop() {
1050
1050
) ;
1051
1051
}
1052
1052
1053
+ #[ test]
1054
+ fn test_from_iter_specialization_panic_during_drop_leaks ( ) {
1055
+ static mut DROP_COUNTER : usize = 0 ;
1056
+
1057
+ #[ derive( Debug ) ]
1058
+ enum Droppable {
1059
+ DroppedTwice ( Box < i32 > ) ,
1060
+ PanicOnDrop ,
1061
+ }
1062
+
1063
+ impl Drop for Droppable {
1064
+ fn drop ( & mut self ) {
1065
+ match self {
1066
+ Droppable :: DroppedTwice ( _) => {
1067
+ unsafe {
1068
+ DROP_COUNTER += 1 ;
1069
+ }
1070
+ println ! ( "Dropping!" )
1071
+ }
1072
+ Droppable :: PanicOnDrop => {
1073
+ if !std:: thread:: panicking ( ) {
1074
+ panic ! ( ) ;
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ let _ = std:: panic:: catch_unwind ( AssertUnwindSafe ( || {
1082
+ let v = vec ! [ Droppable :: DroppedTwice ( Box :: new( 123 ) ) , Droppable :: PanicOnDrop ] ;
1083
+ let _ = v. into_iter ( ) . take ( 0 ) . collect :: < Vec < _ > > ( ) ;
1084
+ } ) ) ;
1085
+
1086
+ assert_eq ! ( unsafe { DROP_COUNTER } , 1 ) ;
1087
+ }
1088
+
1053
1089
#[ test]
1054
1090
fn test_cow_from ( ) {
1055
1091
let borrowed: & [ _ ] = & [ "borrowed" , "(slice)" ] ;
You can’t perform that action at this time.
0 commit comments