From a239d5bf0e12ff172d5b17c4074d7d98ff2a6c1a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 12 Jun 2024 13:15:02 +0200 Subject: [PATCH 1/5] Clarify doc comment. --- core/src/panic/panic_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/panic/panic_info.rs b/core/src/panic/panic_info.rs index df8f441bf3533..a593abc86058a 100644 --- a/core/src/panic/panic_info.rs +++ b/core/src/panic/panic_info.rs @@ -72,7 +72,7 @@ impl<'a> PanicInfo<'a> { /// Returns the payload associated with the panic. /// - /// On `core::panic::PanicInfo`, this method never returns anything useful. + /// On this type, `core::panic::PanicInfo`, this method never returns anything useful. /// It only exists because of compatibility with [`std::panic::PanicHookInfo`], /// which used to be the same type. /// From 15677e9f865ee48b5241781287ee19eab47e59e4 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 12 Jun 2024 13:15:17 +0200 Subject: [PATCH 2/5] Fix deprecation version. --- core/src/panic/panic_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/panic/panic_info.rs b/core/src/panic/panic_info.rs index a593abc86058a..1925f8e8eac96 100644 --- a/core/src/panic/panic_info.rs +++ b/core/src/panic/panic_info.rs @@ -80,7 +80,7 @@ impl<'a> PanicInfo<'a> { /// /// [`std::panic::PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html /// [`std::panic::PanicHookInfo::payload`]: ../../std/panic/struct.PanicHookInfo.html#method.payload - #[deprecated(since = "1.77.0", note = "this never returns anything useful")] + #[deprecated(since = "CURRENT_RUSTC_VERSION", note = "this never returns anything useful")] #[stable(feature = "panic_hooks", since = "1.10.0")] #[allow(deprecated, deprecated_in_future)] pub fn payload(&self) -> &(dyn crate::any::Any + Send) { From 249d63e985cc48bbcf928c0fcd8ad3d56af73e8f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 12 Jun 2024 13:15:29 +0200 Subject: [PATCH 3/5] Use payload_as_str instead of two downcasts. --- std/src/panic.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/std/src/panic.rs b/std/src/panic.rs index 5282c00fccaf0..c5d1a893ee809 100644 --- a/std/src/panic.rs +++ b/std/src/panic.rs @@ -202,10 +202,7 @@ impl fmt::Display for PanicHookInfo<'_> { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("panicked at ")?; self.location.fmt(formatter)?; - if let Some(payload) = self.payload.downcast_ref::<&'static str>() { - formatter.write_str(":\n")?; - formatter.write_str(payload)?; - } else if let Some(payload) = self.payload.downcast_ref::() { + if let Some(payload) = self.payload_as_str() { formatter.write_str(":\n")?; formatter.write_str(payload)?; } From bc5e618edd3dea8ce5eaf7c6b8020af2a04341f4 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 12 Jun 2024 13:17:42 +0200 Subject: [PATCH 4/5] Update doc comment on PanicInfo::message(). --- core/src/panic/panic_info.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/panic/panic_info.rs b/core/src/panic/panic_info.rs index 1925f8e8eac96..c8e507c690e29 100644 --- a/core/src/panic/panic_info.rs +++ b/core/src/panic/panic_info.rs @@ -29,9 +29,8 @@ impl<'a> PanicInfo<'a> { PanicInfo { location, message, can_unwind, force_no_backtrace } } - /// If the `panic!` macro from the `core` crate (not from `std`) - /// was used with a formatting string and some additional arguments, - /// returns that message ready to be used for example with [`fmt::write`] + /// The message that was given to the `panic!` macro, + /// ready to be formatted with e.g. [`fmt::write`]. #[must_use] #[unstable(feature = "panic_info_message", issue = "66745")] pub fn message(&self) -> fmt::Arguments<'_> { From 3acb41fba7ca75b99d2afe7574f8cae0633dd56d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 12 Jun 2024 13:23:21 +0200 Subject: [PATCH 5/5] Fix deprecated version. --- core/src/panic/panic_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/panic/panic_info.rs b/core/src/panic/panic_info.rs index c8e507c690e29..78cf1d2e98eca 100644 --- a/core/src/panic/panic_info.rs +++ b/core/src/panic/panic_info.rs @@ -79,7 +79,7 @@ impl<'a> PanicInfo<'a> { /// /// [`std::panic::PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html /// [`std::panic::PanicHookInfo::payload`]: ../../std/panic/struct.PanicHookInfo.html#method.payload - #[deprecated(since = "CURRENT_RUSTC_VERSION", note = "this never returns anything useful")] + #[deprecated(since = "1.81.0", note = "this never returns anything useful")] #[stable(feature = "panic_hooks", since = "1.10.0")] #[allow(deprecated, deprecated_in_future)] pub fn payload(&self) -> &(dyn crate::any::Any + Send) {