File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1+ use alloc:: boxed:: Box ;
12use std:: borrow:: Cow ;
23use std:: cell:: Cell ;
34use std:: collections:: TryReserveError :: * ;
@@ -1056,14 +1057,14 @@ fn test_from_iter_specialization_panic_during_drop_leaks() {
10561057
10571058 #[ derive( Debug ) ]
10581059 enum Droppable {
1059- DroppedTwice ( Box < i32 > ) ,
1060+ DroppedTwice ,
10601061 PanicOnDrop ,
10611062 }
10621063
10631064 impl Drop for Droppable {
10641065 fn drop ( & mut self ) {
10651066 match self {
1066- Droppable :: DroppedTwice ( _ ) => {
1067+ Droppable :: DroppedTwice => {
10671068 unsafe {
10681069 DROP_COUNTER += 1 ;
10691070 }
@@ -1078,12 +1079,21 @@ fn test_from_iter_specialization_panic_during_drop_leaks() {
10781079 }
10791080 }
10801081
1082+ let mut to_free: * mut Droppable = core:: ptr:: null_mut ( ) ;
1083+ let mut cap = 0 ;
1084+
10811085 let _ = std:: panic:: catch_unwind ( AssertUnwindSafe ( || {
1082- let v = vec ! [ Droppable :: DroppedTwice ( Box :: new( 123 ) ) , Droppable :: PanicOnDrop ] ;
1086+ let mut v = vec ! [ Droppable :: DroppedTwice , Droppable :: PanicOnDrop ] ;
1087+ to_free = v. as_mut_ptr ( ) ;
1088+ cap = v. capacity ( ) ;
10831089 let _ = v. into_iter ( ) . take ( 0 ) . collect :: < Vec < _ > > ( ) ;
10841090 } ) ) ;
10851091
10861092 assert_eq ! ( unsafe { DROP_COUNTER } , 1 ) ;
1093+ // clean up the leak to keep miri happy
1094+ unsafe {
1095+ Vec :: from_raw_parts ( to_free, 0 , cap) ;
1096+ }
10871097}
10881098
10891099#[ test]
You can’t perform that action at this time.
0 commit comments