Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47f359b

Browse files
committedJun 11, 2024
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.
1 parent 701d6a2 commit 47f359b

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed
 

‎std/src/panic.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,14 @@ pub struct PanicInfo<'a> {
4444
}
4545

4646
impl<'a> PanicInfo<'a> {
47-
#[unstable(feature = "panic_internals", issue = "none")]
48-
#[doc(hidden)]
4947
#[inline]
50-
pub fn internal_constructor(
48+
pub(crate) fn new(
5149
location: &'a Location<'a>,
50+
payload: &'a (dyn Any + Send),
5251
can_unwind: bool,
5352
force_no_backtrace: bool,
5453
) -> Self {
55-
struct NoPayload;
56-
PanicInfo { payload: &NoPayload, location, can_unwind, force_no_backtrace }
57-
}
58-
59-
#[unstable(feature = "panic_internals", issue = "none")]
60-
#[doc(hidden)]
61-
#[inline]
62-
pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) {
63-
self.payload = info;
54+
PanicInfo { payload, location, can_unwind, force_no_backtrace }
6455
}
6556

6657
/// Returns the payload associated with the panic.

‎std/src/panicking.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,7 @@ fn rust_panic_with_hook(
775775
crate::sys::abort_internal();
776776
}
777777

778-
let mut info = PanicInfo::internal_constructor(location, can_unwind, force_no_backtrace);
779-
let hook = HOOK.read().unwrap_or_else(PoisonError::into_inner);
780-
match *hook {
778+
match *HOOK.read().unwrap_or_else(PoisonError::into_inner) {
781779
// Some platforms (like wasm) know that printing to stderr won't ever actually
782780
// print anything, and if that's the case we can skip the default
783781
// hook. Since string formatting happens lazily when calling `payload`
@@ -786,15 +784,12 @@ fn rust_panic_with_hook(
786784
// formatting.)
787785
Hook::Default if panic_output().is_none() => {}
788786
Hook::Default => {
789-
info.set_payload(payload.get());
790-
default_hook(&info);
787+
default_hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
791788
}
792789
Hook::Custom(ref hook) => {
793-
info.set_payload(payload.get());
794-
hook(&info);
790+
hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
795791
}
796-
};
797-
drop(hook);
792+
}
798793

799794
// Indicate that we have finished executing the panic hook. After this point
800795
// it is fine if there is a panic while executing destructors, as long as it

0 commit comments

Comments
 (0)
Failed to load comments.