@@ -248,13 +248,7 @@ fn default_hook(info: &PanicInfo<'_>) { |
|
|
248 |
248 |
// The current implementation always returns `Some`. |
249 |
249 |
let location = info.location().unwrap(); |
250 |
250 |
|
251 |
|
-let msg = match info.payload().downcast_ref::<&'static str>() { |
252 |
|
-Some(s) => *s, |
253 |
|
-None => match info.payload().downcast_ref::<String>() { |
254 |
|
-Some(s) => &s[..], |
255 |
|
-None => "Box", |
256 |
|
-}, |
257 |
|
-}; |
|
251 |
+let msg = payload_as_str(info.payload()); |
258 |
252 |
let thread = thread::try_current(); |
259 |
253 |
let name = thread.as_ref().and_then(|t |
260 |
254 |
|
@@ -731,6 +725,16 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! { |
|
|
731 |
725 |
} |
732 |
726 |
} |
733 |
727 |
|
|
728 |
+fn payload_as_str(payload: &dyn Any) -> &str { |
|
729 |
+if let Some(&s) = payload.downcast_ref::<&'static str>() { |
|
730 |
+ s |
|
731 |
+} else if let Some(s) = payload.downcast_ref::<String>() { |
|
732 |
+ s.as_str() |
|
733 |
+} else { |
|
734 |
+"Box" |
|
735 |
+} |
|
736 |
+} |
|
737 |
+ |
734 |
738 |
/// Central point for dispatching panics. |
735 |
739 |
/// |
736 |
740 |
/// Executes the primary logic for a panic, including checking for recursive |