@@ -1110,23 +1110,31 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
1110
1110
}
1111
1111
1112
1112
#[ test]
1113
- fn test_from_iter_specialization_panic_during_drop_leaks ( ) {
1114
- static mut DROP_COUNTER : usize = 0 ;
1113
+ fn test_from_iter_specialization_panic_during_drop_doesnt_leak ( ) {
1114
+ static mut DROP_COUNTER_SHOULD_BE_DROPPED : usize = 0 ;
1115
+ static mut DROP_COUNTER_DROPPED_TWICE : usize = 0 ;
1115
1116
1116
1117
#[ derive( Debug ) ]
1117
1118
enum Droppable {
1119
+ ShouldBeDropped ,
1118
1120
DroppedTwice ( Box < i32 > ) ,
1119
1121
PanicOnDrop ,
1120
1122
}
1121
1123
1122
1124
impl Drop for Droppable {
1123
1125
fn drop ( & mut self ) {
1124
1126
match self {
1127
+ Droppable :: ShouldBeDropped => {
1128
+ unsafe {
1129
+ DROP_COUNTER_SHOULD_BE_DROPPED += 1 ;
1130
+ }
1131
+ println ! ( "Dropping ShouldBeDropped!" )
1132
+ }
1125
1133
Droppable :: DroppedTwice ( _) => {
1126
1134
unsafe {
1127
- DROP_COUNTER += 1 ;
1135
+ DROP_COUNTER_DROPPED_TWICE += 1 ;
1128
1136
}
1129
- println ! ( "Dropping!" )
1137
+ println ! ( "Dropping DroppedTwice !" )
1130
1138
}
1131
1139
Droppable :: PanicOnDrop => {
1132
1140
if !std:: thread:: panicking ( ) {
@@ -1137,21 +1145,17 @@ fn test_from_iter_specialization_panic_during_drop_leaks() {
1137
1145
}
1138
1146
}
1139
1147
1140
- let mut to_free: * mut Droppable = core:: ptr:: null_mut ( ) ;
1141
- let mut cap = 0 ;
1142
-
1143
1148
let _ = std:: panic:: catch_unwind ( AssertUnwindSafe ( || {
1144
- let mut v = vec ! [ Droppable :: DroppedTwice ( Box :: new( 123 ) ) , Droppable :: PanicOnDrop ] ;
1145
- to_free = v. as_mut_ptr ( ) ;
1146
- cap = v. capacity ( ) ;
1147
- let _ = v. into_iter ( ) . take ( 0 ) . collect :: < Vec < _ > > ( ) ;
1149
+ let v = vec ! [
1150
+ Droppable :: ShouldBeDropped ,
1151
+ Droppable :: DroppedTwice ( Box :: new( 123 ) ) ,
1152
+ Droppable :: PanicOnDrop ,
1153
+ ] ;
1154
+ let _ = v. into_iter ( ) . take ( 1 ) . collect :: < Vec < _ > > ( ) ;
1148
1155
} ) ) ;
1149
1156
1150
- assert_eq ! ( unsafe { DROP_COUNTER } , 1 ) ;
1151
- // clean up the leak to keep miri happy
1152
- unsafe {
1153
- drop ( Vec :: from_raw_parts ( to_free, 0 , cap) ) ;
1154
- }
1157
+ assert_eq ! ( unsafe { DROP_COUNTER_SHOULD_BE_DROPPED } , 1 ) ;
1158
+ assert_eq ! ( unsafe { DROP_COUNTER_DROPPED_TWICE } , 1 ) ;
1155
1159
}
1156
1160
1157
1161
// regression test for issue #85322. Peekable previously implemented InPlaceIterable,
0 commit comments