about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-11-22 23:21:20 +0100
committerRalf Jung <post@ralfj.de>2019-11-22 23:21:20 +0100
commit3277209af5c3369cbf1786d25cbf48c9a131996b (patch)
tree5c9aae05e9e4949ed569e0e4519238845084693c /src/liballoc
parent1e91e4e20a5d6e50e281c6e87a3a61cc735e266f (diff)
downloadrust-3277209af5c3369cbf1786d25cbf48c9a131996b.tar.gz
rust-3277209af5c3369cbf1786d25cbf48c9a131996b.zip
use catch_panic instead of thread::spawn to catch panics
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/tests/slice.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs
index ad2cd7c95eb..62b33c02cae 100644
--- a/src/liballoc/tests/slice.rs
+++ b/src/liballoc/tests/slice.rs
@@ -4,7 +4,6 @@ use std::mem;
 use std::panic;
 use std::rc::Rc;
 use std::sync::atomic::{Ordering::Relaxed, AtomicUsize};
-use std::thread;
 
 use rand::{Rng, RngCore, thread_rng};
 use rand::seq::SliceRandom;
@@ -1406,11 +1405,10 @@ fn test_box_slice_clone() {
 #[test]
 #[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
 #[cfg_attr(target_os = "emscripten", ignore)]
-#[cfg(not(miri))] // Miri does not support threads
+#[cfg(not(miri))] // Miri does not support catching panics
 fn test_box_slice_clone_panics() {
     use std::sync::Arc;
     use std::sync::atomic::{AtomicUsize, Ordering};
-    use std::thread::spawn;
 
     struct Canary {
         count: Arc<AtomicUsize>,
@@ -1446,7 +1444,7 @@ fn test_box_slice_clone_panics() {
         panics: true,
     };
 
-    spawn(move || {
+    std::panic::catch_unwind(move || {
             // When xs is dropped, +5.
             let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary]
                 .into_boxed_slice();
@@ -1454,7 +1452,6 @@ fn test_box_slice_clone_panics() {
             // When panic is cloned, +3.
             xs.clone();
         })
-        .join()
         .unwrap_err();
 
     // Total = 8
@@ -1566,7 +1563,7 @@ macro_rules! test {
             }
 
             let v = $input.to_owned();
-            let _ = thread::spawn(move || {
+            let _ = std::panic::catch_unwind(move || {
                 let mut v = v;
                 let mut panic_countdown = panic_countdown;
                 v.$func(|a, b| {
@@ -1577,7 +1574,7 @@ macro_rules! test {
                     panic_countdown -= 1;
                     a.cmp(b)
                 })
-            }).join();
+            });
 
             // Check that the number of things dropped is exactly
             // what we expect (i.e., the contents of `v`).
@@ -1598,7 +1595,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
 
 #[test]
 #[cfg_attr(target_os = "emscripten", ignore)] // no threads
-#[cfg(not(miri))] // Miri does not support threads
+#[cfg(not(miri))] // Miri does not support catching panics
 fn panic_safe() {
     let prev = panic::take_hook();
     panic::set_hook(Box::new(move |info| {