From 47f359bc210e8a29aa42c239d61f43ece67e5e9c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 2 Oct 2023 14:14:15 +0200 Subject: [PATCH] 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. --- std/src/panic.rs | 15 +++------------ std/src/panicking.rs | 13 ++++--------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/std/src/panic.rs b/std/src/panic.rs index e2d182b4ba07e..7adbce859f56c 100644 --- a/std/src/panic.rs +++ b/std/src/panic.rs @@ -44,23 +44,14 @@ pub struct PanicInfo<'a> { } impl<'a> PanicInfo<'a> { - #[unstable(feature = "panic_internals", issue = "none")] - #[doc(hidden)] #[inline] - pub fn internal_constructor( + pub(crate) fn new( location: &'a Location<'a>, + payload: &'a (dyn Any + Send), can_unwind: bool, force_no_backtrace: bool, ) -> Self { - struct NoPayload; - 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; + PanicInfo { payload, location, can_unwind, force_no_backtrace } } /// Returns the payload associated with the panic. diff --git a/std/src/panicking.rs b/std/src/panicking.rs index d6ef8f0dbbee3..6d6aca01561a1 100644 --- a/std/src/panicking.rs +++ b/std/src/panicking.rs @@ -775,9 +775,7 @@ fn rust_panic_with_hook( crate::sys::abort_internal(); } - let mut info = PanicInfo::internal_constructor(location, can_unwind, force_no_backtrace); - let hook = HOOK.read().unwrap_or_else(PoisonError::into_inner); - match *hook { + match *HOOK.read().unwrap_or_else(PoisonError::into_inner) { // 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 // hook. Since string formatting happens lazily when calling `payload` @@ -786,15 +784,12 @@ fn rust_panic_with_hook( // formatting.) Hook::Default if panic_output().is_none() => {} Hook::Default => { - info.set_payload(payload.get()); - default_hook(&info); + default_hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace)); } Hook::Custom(ref hook) => { - info.set_payload(payload.get()); - hook(&info); + hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace)); } - }; - drop(hook); + } // 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