diff options
| author | Badel2 <2badel2@gmail.com> | 2022-01-07 17:04:33 +0100 |
|---|---|---|
| committer | Badel2 <2badel2@gmail.com> | 2022-01-08 00:57:59 +0100 |
| commit | 8ef3ce866e2f20bdcc567e2f7012f81ce2e60298 (patch) | |
| tree | 1764db087c7b3bb38aa060ba67b985d4ec63f975 /src | |
| parent | 8bdf5c3de6c6e4e01f7f6241cd0f2a606c7486df (diff) | |
Change panic::update_hook to simplify usage
And to remove possibility of panics while changing the panic handler, because that resulted in a double panic.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/panics/panic-handler-chain-update-hook.rs | 36 | ||||
| -rw-r--r-- | src/test/ui/panics/panic-while-updating-hook.rs | 16 |
2 files changed, 36 insertions, 16 deletions
diff --git a/src/test/ui/panics/panic-handler-chain-update-hook.rs b/src/test/ui/panics/panic-handler-chain-update-hook.rs new file mode 100644 index 00000000000..4dd08ba4ad4 --- /dev/null +++ b/src/test/ui/panics/panic-handler-chain-update-hook.rs @@ -0,0 +1,36 @@ +// run-pass +// needs-unwind +#![allow(stable_features)] + +// ignore-emscripten no threads support + +#![feature(std_panic)] +#![feature(panic_update_hook)] + +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::panic; +use std::thread; + +static A: AtomicUsize = AtomicUsize::new(0); +static B: AtomicUsize = AtomicUsize::new(0); +static C: AtomicUsize = AtomicUsize::new(0); + +fn main() { + panic::set_hook(Box::new(|_| { A.fetch_add(1, Ordering::SeqCst); })); + panic::update_hook(|prev, info| { + B.fetch_add(1, Ordering::SeqCst); + prev(info); + }); + panic::update_hook(|prev, info| { + C.fetch_add(1, Ordering::SeqCst); + prev(info); + }); + + let _ = thread::spawn(|| { + panic!(); + }).join(); + + assert_eq!(1, A.load(Ordering::SeqCst)); + assert_eq!(1, B.load(Ordering::SeqCst)); + assert_eq!(1, C.load(Ordering::SeqCst)); +} diff --git a/src/test/ui/panics/panic-while-updating-hook.rs b/src/test/ui/panics/panic-while-updating-hook.rs deleted file mode 100644 index 8c95f1b8b78..00000000000 --- a/src/test/ui/panics/panic-while-updating-hook.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-fail -// error-pattern: panicked while processing panic -#![allow(stable_features)] - -// ignore-emscripten no threads support - -#![feature(std_panic)] -#![feature(panic_update_hook)] - -use std::panic; - -fn main() { - panic::update_hook(|_prev| { - panic!("inside update_hook"); - }) -} |
