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 027c82e

Browse files
authoredJun 12, 2024
Rollup merge of rust-lang#126322 - m-ou-se:panicinfo-and-panicinfo-2, r=RalfJung
Follow up to splitting core's PanicInfo and std's PanicInfo
2 parents db03ec6 + 3acb41f commit 027c82e

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed
 

‎core/src/panic/panic_info.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ impl<'a> PanicInfo<'a> {
2929
PanicInfo { location, message, can_unwind, force_no_backtrace }
3030
}
3131

32-
/// If the `panic!` macro from the `core` crate (not from `std`)
33-
/// was used with a formatting string and some additional arguments,
34-
/// returns that message ready to be used for example with [`fmt::write`]
32+
/// The message that was given to the `panic!` macro,
33+
/// ready to be formatted with e.g. [`fmt::write`].
3534
#[must_use]
3635
#[unstable(feature = "panic_info_message", issue = "66745")]
3736
pub fn message(&self) -> fmt::Arguments<'_> {
@@ -72,15 +71,15 @@ impl<'a> PanicInfo<'a> {
7271

7372
/// Returns the payload associated with the panic.
7473
///
75-
/// On `core::panic::PanicInfo`, this method never returns anything useful.
74+
/// On this type, `core::panic::PanicInfo`, this method never returns anything useful.
7675
/// It only exists because of compatibility with [`std::panic::PanicHookInfo`],
7776
/// which used to be the same type.
7877
///
7978
/// See [`std::panic::PanicHookInfo::payload`].
8079
///
8180
/// [`std::panic::PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html
8281
/// [`std::panic::PanicHookInfo::payload`]: ../../std/panic/struct.PanicHookInfo.html#method.payload
83-
#[deprecated(since = "1.77.0", note = "this never returns anything useful")]
82+
#[deprecated(since = "1.81.0", note = "this never returns anything useful")]
8483
#[stable(feature = "panic_hooks", since = "1.10.0")]
8584
#[allow(deprecated, deprecated_in_future)]
8685
pub fn payload(&self) -> &(dyn crate::any::Any + Send) {

‎std/src/panic.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ impl fmt::Display for PanicHookInfo<'_> {
202202
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
203203
formatter.write_str("panicked at ")?;
204204
self.location.fmt(formatter)?;
205-
if let Some(payload) = self.payload.downcast_ref::<&'static str>() {
206-
formatter.write_str(":\n")?;
207-
formatter.write_str(payload)?;
208-
} else if let Some(payload) = self.payload.downcast_ref::<String>() {
205+
if let Some(payload) = self.payload_as_str() {
209206
formatter.write_str(":\n")?;
210207
formatter.write_str(payload)?;
211208
}

0 commit comments

Comments
 (0)
Failed to load comments.