@@ -4,7 +4,6 @@ use std::mem;
44use std:: panic;
55use std:: rc:: Rc ;
66use std:: sync:: atomic:: { Ordering :: Relaxed , AtomicUsize } ;
7- use std:: thread;
87
98use rand:: { Rng , RngCore , thread_rng} ;
109use rand:: seq:: SliceRandom ;
@@ -1406,11 +1405,9 @@ fn test_box_slice_clone() {
14061405#[ test]
14071406#[ allow( unused_must_use) ] // here, we care about the side effects of `.clone()`
14081407#[ cfg_attr( target_os = "emscripten" , ignore) ]
1409- #[ cfg( not( miri) ) ] // Miri does not support threads
14101408fn test_box_slice_clone_panics ( ) {
14111409 use std:: sync:: Arc ;
14121410 use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
1413- use std:: thread:: spawn;
14141411
14151412 struct Canary {
14161413 count : Arc < AtomicUsize > ,
@@ -1446,15 +1443,14 @@ fn test_box_slice_clone_panics() {
14461443 panics : true ,
14471444 } ;
14481445
1449- spawn ( move || {
1446+ std :: panic :: catch_unwind ( move || {
14501447 // When xs is dropped, +5.
14511448 let xs = vec ! [ canary. clone( ) , canary. clone( ) , canary. clone( ) , panic, canary]
14521449 . into_boxed_slice ( ) ;
14531450
14541451 // When panic is cloned, +3.
14551452 xs. clone ( ) ;
14561453 } )
1457- . join ( )
14581454 . unwrap_err ( ) ;
14591455
14601456 // Total = 8
@@ -1566,7 +1562,7 @@ macro_rules! test {
15661562 }
15671563
15681564 let v = $input. to_owned( ) ;
1569- let _ = thread :: spawn ( move || {
1565+ let _ = std :: panic :: catch_unwind ( move || {
15701566 let mut v = v;
15711567 let mut panic_countdown = panic_countdown;
15721568 v. $func( |a, b| {
@@ -1577,7 +1573,7 @@ macro_rules! test {
15771573 panic_countdown -= 1 ;
15781574 a. cmp( b)
15791575 } )
1580- } ) . join ( ) ;
1576+ } ) ;
15811577
15821578 // Check that the number of things dropped is exactly
15831579 // what we expect (i.e., the contents of `v`).
@@ -1598,7 +1594,6 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
15981594
15991595#[ test]
16001596#[ cfg_attr( target_os = "emscripten" , ignore) ] // no threads
1601- #[ cfg( not( miri) ) ] // Miri does not support threads
16021597fn panic_safe ( ) {
16031598 let prev = panic:: take_hook ( ) ;
16041599 panic:: set_hook ( Box :: new ( move |info| {
@@ -1609,8 +1604,18 @@ fn panic_safe() {
16091604
16101605 let mut rng = thread_rng ( ) ;
16111606
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 {
16141619 for & has_runs in & [ false , true ] {
16151620 let mut input = ( 0 ..len)
16161621 . map ( |id| {
@@ -1643,6 +1648,9 @@ fn panic_safe() {
16431648 }
16441649 }
16451650 }
1651+
1652+ // Set default panic hook again.
1653+ drop ( panic:: take_hook ( ) ) ;
16461654}
16471655
16481656#[ test]
0 commit comments