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;
#[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>,
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();
// When panic is cloned, +3.
xs.clone();
})
- .join()
.unwrap_err();
// Total = 8
}
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| {
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`).
#[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| {