about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-01-23 17:24:19 +0100
committerSimon Sapin <simon.sapin@exyr.org>2018-01-23 17:24:19 +0100
commit9e96c1ef7fcac0ac85b3c9160f5486e91dd27dd2 (patch)
tree2f7b1e2868866deaf93f02a617dc92951121c329 /src
parent2f98f4b12b8fd5d93ffff3d7b98931b3f1f2b07a (diff)
downloadrust-9e96c1ef7fcac0ac85b3c9160f5486e91dd27dd2.tar.gz
rust-9e96c1ef7fcac0ac85b3c9160f5486e91dd27dd2.zip
Add an unstable PanicInfo::message(&self) -> Option<&fmt::Arguments> method
Diffstat (limited to 'src')
-rw-r--r--src/libcore/panic.rs19
-rw-r--r--src/libstd/panicking.rs1
2 files changed, 18 insertions, 2 deletions
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<Any + Send>,
     unsafe {
         let info = PanicInfo::internal_constructor(
             &*msg,
+            None,
             Location::internal_constructor(file, line, col),
         );
         HOOK_LOCK.read();