@@ -4,7 +4,6 @@ use std::mem;
4
4
use std:: panic;
5
5
use std:: rc:: Rc ;
6
6
use std:: sync:: atomic:: { Ordering :: Relaxed , AtomicUsize } ;
7
- use std:: thread;
8
7
9
8
use rand:: { Rng , RngCore , thread_rng} ;
10
9
use rand:: seq:: SliceRandom ;
@@ -1406,11 +1405,9 @@ fn test_box_slice_clone() {
1406
1405
#[ test]
1407
1406
#[ allow( unused_must_use) ] // here, we care about the side effects of `.clone()`
1408
1407
#[ cfg_attr( target_os = "emscripten" , ignore) ]
1409
- #[ cfg( not( miri) ) ] // Miri does not support threads
1410
1408
fn test_box_slice_clone_panics ( ) {
1411
1409
use std:: sync:: Arc ;
1412
1410
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
1413
- use std:: thread:: spawn;
1414
1411
1415
1412
struct Canary {
1416
1413
count : Arc < AtomicUsize > ,
@@ -1446,15 +1443,14 @@ fn test_box_slice_clone_panics() {
1446
1443
panics : true ,
1447
1444
} ;
1448
1445
1449
- spawn ( move || {
1446
+ std :: panic :: catch_unwind ( move || {
1450
1447
// When xs is dropped, +5.
1451
1448
let xs = vec ! [ canary. clone( ) , canary. clone( ) , canary. clone( ) , panic, canary]
1452
1449
. into_boxed_slice ( ) ;
1453
1450
1454
1451
// When panic is cloned, +3.
1455
1452
xs. clone ( ) ;
1456
1453
} )
1457
- . join ( )
1458
1454
. unwrap_err ( ) ;
1459
1455
1460
1456
// Total = 8
@@ -1566,7 +1562,7 @@ macro_rules! test {
1566
1562
}
1567
1563
1568
1564
let v = $input. to_owned( ) ;
1569
- let _ = thread :: spawn ( move || {
1565
+ let _ = std :: panic :: catch_unwind ( move || {
1570
1566
let mut v = v;
1571
1567
let mut panic_countdown = panic_countdown;
1572
1568
v. $func( |a, b| {
@@ -1577,7 +1573,7 @@ macro_rules! test {
1577
1573
panic_countdown -= 1 ;
1578
1574
a. cmp( b)
1579
1575
} )
1580
- } ) . join ( ) ;
1576
+ } ) ;
1581
1577
1582
1578
// Check that the number of things dropped is exactly
1583
1579
// what we expect (i.e., the contents of `v`).
@@ -1598,7 +1594,6 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
1598
1594
1599
1595
#[ test]
1600
1596
#[ cfg_attr( target_os = "emscripten" , ignore) ] // no threads
1601
- #[ cfg( not( miri) ) ] // Miri does not support threads
1602
1597
fn panic_safe ( ) {
1603
1598
let prev = panic:: take_hook ( ) ;
1604
1599
panic:: set_hook ( Box :: new ( move |info| {
@@ -1609,8 +1604,18 @@ fn panic_safe() {
1609
1604
1610
1605
let mut rng = thread_rng ( ) ;
1611
1606
1612
- for len in ( 1 ..20 ) . chain ( 70 ..MAX_LEN ) {
1613
- for & modulus in & [ 5 , 20 , 50 ] {
1607
+ #[ cfg( not( miri) ) ] // Miri is too slow
1608
+ let lens = ( 1 ..20 ) . chain ( 70 ..MAX_LEN ) ;
1609
+ #[ cfg( not( miri) ) ] // Miri is too slow
1610
+ let moduli = & [ 5 , 20 , 50 ] ;
1611
+
1612
+ #[ cfg( miri) ]
1613
+ let lens = ( 1 ..13 ) ;
1614
+ #[ cfg( miri) ]
1615
+ let moduli = & [ 10 ] ;
1616
+
1617
+ for len in lens {
1618
+ for & modulus in moduli {
1614
1619
for & has_runs in & [ false , true ] {
1615
1620
let mut input = ( 0 ..len)
1616
1621
. map ( |id| {
@@ -1643,6 +1648,9 @@ fn panic_safe() {
1643
1648
}
1644
1649
}
1645
1650
}
1651
+
1652
+ // Set default panic hook again.
1653
+ drop ( panic:: take_hook ( ) ) ;
1646
1654
}
1647
1655
1648
1656
#[ test]
0 commit comments