1
Fork 0

Remove std::panic::PanicInfo::internal_constructor+set_payload.

We can just set the payload immediately in the constructor,
and the constructor does not need to be public.
This commit is contained in:
Mara Bos 2023-10-02 14:14:15 +02:00
parent 0266bbf6e4
commit 0642cb2994
2 changed files with 7 additions and 21 deletions

View file

@ -44,23 +44,14 @@ pub struct PanicInfo<'a> {
} }
impl<'a> PanicInfo<'a> { impl<'a> PanicInfo<'a> {
#[unstable(feature = "panic_internals", issue = "none")]
#[doc(hidden)]
#[inline] #[inline]
pub fn internal_constructor( pub(crate) fn new(
location: &'a Location<'a>, location: &'a Location<'a>,
payload: &'a (dyn Any + Send),
can_unwind: bool, can_unwind: bool,
force_no_backtrace: bool, force_no_backtrace: bool,
) -> Self { ) -> Self {
struct NoPayload; PanicInfo { payload, location, can_unwind, force_no_backtrace }
PanicInfo { payload: &NoPayload, location, can_unwind, force_no_backtrace }
}
#[unstable(feature = "panic_internals", issue = "none")]
#[doc(hidden)]
#[inline]
pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) {
self.payload = info;
} }
/// Returns the payload associated with the panic. /// Returns the payload associated with the panic.

View file

@ -775,9 +775,7 @@ fn rust_panic_with_hook(
crate::sys::abort_internal(); crate::sys::abort_internal();
} }
let mut info = PanicInfo::internal_constructor(location, can_unwind, force_no_backtrace); match *HOOK.read().unwrap_or_else(PoisonError::into_inner) {
let hook = HOOK.read().unwrap_or_else(PoisonError::into_inner);
match *hook {
// Some platforms (like wasm) know that printing to stderr won't ever actually // Some platforms (like wasm) know that printing to stderr won't ever actually
// print anything, and if that's the case we can skip the default // print anything, and if that's the case we can skip the default
// hook. Since string formatting happens lazily when calling `payload` // hook. Since string formatting happens lazily when calling `payload`
@ -786,15 +784,12 @@ fn rust_panic_with_hook(
// formatting.) // formatting.)
Hook::Default if panic_output().is_none() => {} Hook::Default if panic_output().is_none() => {}
Hook::Default => { Hook::Default => {
info.set_payload(payload.get()); default_hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
default_hook(&info);
} }
Hook::Custom(ref hook) => { Hook::Custom(ref hook) => {
info.set_payload(payload.get()); hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
hook(&info);
} }
}; }
drop(hook);
// Indicate that we have finished executing the panic hook. After this point // Indicate that we have finished executing the panic hook. After this point
// it is fine if there is a panic while executing destructors, as long as it // it is fine if there is a panic while executing destructors, as long as it