Use payload_as_str instead of two downcasts.

This commit is contained in:
Mara Bos 2024-06-12 13:15:29 +02:00
parent 1dc7952303
commit 2944eab5e6

View File

@ -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::<String>() {
if let Some(payload) = self.payload_as_str() {
formatter.write_str(":\n")?;
formatter.write_str(payload)?;
}