]> git.lizzy.rs Git - rust.git/commitdiff
Add an unstable PanicInfo::message(&self) -> Option<&fmt::Arguments> method
authorSimon Sapin <simon.sapin@exyr.org>
Tue, 23 Jan 2018 16:24:19 +0000 (17:24 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 23 Jan 2018 16:24:19 +0000 (17:24 +0100)
src/libcore/panic.rs
src/libstd/panicking.rs

index dbfe531063b7d4048b5749c8b79f4b3d8cab6fd4..2dfd950225c36fd2e8b2a0902a41ad951392c419 100644 (file)
@@ -15,6 +15,7 @@
             issue = "44489")]
 
 use any::Any;
+use fmt;
 
 /// A struct providing information about a panic.
 ///
@@ -38,6 +39,7 @@
 #[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 @@ pub fn payload(&self) -> &(Any + Send) {
         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.
     ///
index a748c89f9d4faf74931847d1ebad686a9066307f..3f5523548ce5723ade95eadd171d3c9775144689 100644 (file)
@@ -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();