Open
Description
I tried this code:
use std::{panic::catch_unwind, thread};
fn main() {
let res = catch_unwind(|| {
thread::scope(|scope| {
scope.spawn(|| panic!("my panic message with useful information"));
});
});
let payload = res.unwrap_err();
let message = payload.downcast_ref::<&str>().unwrap();
dbg!(message);
}
I expected to see this happen: the panic payload from the scoped thread should be forwarded to the main thread using panic::resume_unwind
. The payload passed to panic!
inside the scope should be retrievable there, and there should not be any additional panics.
Instead, this happened: a second panic with no link to the original is caused by the thread::scope
implementation, and the payload is a meaningless "a scoped thread panicked" message.
Meta
rustc --version --verbose
:
rustc 1.85.1
beta and nightly also behave like this