diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index dbfe531063b..2dfd950225c 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -15,6 +15,7 @@ issue = "44489")] use any::Any; +use fmt; /// A struct providing information about a panic. /// @@ -38,6 +39,7 @@ use any::Any; #[derive(Debug)] pub struct PanicInfo<'a> { payload: &'a (Any + Send), + message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>, } @@ -47,8 +49,11 @@ impl<'a> PanicInfo<'a> { and related macros", issue = "0")] #[doc(hidden)] - pub fn internal_constructor(payload: &'a (Any + Send), location: Location<'a>,) -> Self { - PanicInfo { payload, location } + pub fn internal_constructor(payload: &'a (Any + Send), + message: Option<&'a fmt::Arguments<'a>>, + location: Location<'a>) + -> Self { + PanicInfo { payload, location, message } } /// Returns the payload associated with the panic. @@ -73,6 +78,16 @@ impl<'a> PanicInfo<'a> { self.payload } + /// 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`] + /// + /// [`fmt::write`]: ../fmt/fn.write.html + #[unstable(feature = "panic_info_message", issue = "44489")] + pub fn message(&self) -> Option<&fmt::Arguments> { + self.message + } + /// Returns information about the location from which the panic originated, /// if available. /// diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index a748c89f9d4..3f5523548ce 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -391,6 +391,7 @@ fn rust_panic_with_hook(msg: Box, unsafe { let info = PanicInfo::internal_constructor( &*msg, + None, Location::internal_constructor(file, line, col), ); HOOK_LOCK.read();