@@ -1494,33 +1494,40 @@ fn test_clone() {
1494
1494
map. check ( ) ;
1495
1495
}
1496
1496
1497
- #[ test]
1498
- fn test_clone_panic_leak ( ) {
1499
- let a = CrashTestDummy :: new ( 0 ) ;
1500
- let b = CrashTestDummy :: new ( 1 ) ;
1501
- let c = CrashTestDummy :: new ( 2 ) ;
1497
+ fn test_clone_panic_leak ( size : usize ) {
1498
+ for i in 0 ..size {
1499
+ let dummies: Vec < CrashTestDummy > = ( 0 ..size) . map ( |id| CrashTestDummy :: new ( id) ) . collect ( ) ;
1500
+ let map: BTreeMap < _ , ( ) > = dummies
1501
+ . iter ( )
1502
+ . map ( |dummy| {
1503
+ let panic = if dummy. id == i { Panic :: InClone } else { Panic :: Never } ;
1504
+ ( dummy. spawn ( panic) , ( ) )
1505
+ } )
1506
+ . collect ( ) ;
1502
1507
1503
- let mut map = BTreeMap :: new ( ) ;
1504
- map. insert ( a. spawn ( Panic :: Never ) , ( ) ) ;
1505
- map. insert ( b. spawn ( Panic :: InClone ) , ( ) ) ;
1506
- map. insert ( c. spawn ( Panic :: Never ) , ( ) ) ;
1508
+ catch_unwind ( || map. clone ( ) ) . unwrap_err ( ) ;
1509
+ for d in & dummies {
1510
+ assert_eq ! ( d. cloned( ) , if d. id <= i { 1 } else { 0 } , "id={}/{}" , d. id, i) ;
1511
+ assert_eq ! ( d. dropped( ) , if d. id < i { 1 } else { 0 } , "id={}/{}" , d. id, i) ;
1512
+ }
1513
+ assert_eq ! ( map. len( ) , size) ;
1507
1514
1508
- catch_unwind ( || map. clone ( ) ) . unwrap_err ( ) ;
1509
- assert_eq ! ( a. cloned( ) , 1 ) ;
1510
- assert_eq ! ( b. cloned( ) , 1 ) ;
1511
- assert_eq ! ( c. cloned( ) , 0 ) ;
1512
- assert_eq ! ( a. dropped( ) , 1 ) ;
1513
- assert_eq ! ( b. dropped( ) , 0 ) ;
1514
- assert_eq ! ( c. dropped( ) , 0 ) ;
1515
- assert_eq ! ( map. len( ) , 3 ) ;
1515
+ drop ( map) ;
1516
+ for d in & dummies {
1517
+ assert_eq ! ( d. cloned( ) , if d. id <= i { 1 } else { 0 } , "id={}/{}" , d. id, i) ;
1518
+ assert_eq ! ( d. dropped( ) , if d. id < i { 2 } else { 1 } , "id={}/{}" , d. id, i) ;
1519
+ }
1520
+ }
1521
+ }
1516
1522
1517
- drop ( map) ;
1518
- assert_eq ! ( a. cloned( ) , 1 ) ;
1519
- assert_eq ! ( b. cloned( ) , 1 ) ;
1520
- assert_eq ! ( c. cloned( ) , 0 ) ;
1521
- assert_eq ! ( a. dropped( ) , 2 ) ;
1522
- assert_eq ! ( b. dropped( ) , 1 ) ;
1523
- assert_eq ! ( c. dropped( ) , 1 ) ;
1523
+ #[ test]
1524
+ fn test_clone_panic_leak_height_0 ( ) {
1525
+ test_clone_panic_leak ( 3 )
1526
+ }
1527
+
1528
+ #[ test]
1529
+ fn test_clone_panic_leak_height_1 ( ) {
1530
+ test_clone_panic_leak ( MIN_INSERTS_HEIGHT_1 )
1524
1531
}
1525
1532
1526
1533
#[ test]
0 commit comments