about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2018-05-01 03:02:39 +0200
committerJorge Aparicio <jorge@japaric.io>2018-06-03 13:46:19 +0200
commiteaef110890837283a1504eb200cab1eba03650ea (patch)
tree2c43b932ab509c9edfa5055db0ac6f4c6d779cf7 /src
parent63f18e108af98be931465fa0d2e7e998c5542aab (diff)
downloadrust-eaef110890837283a1504eb200cab1eba03650ea.tar.gz
rust-eaef110890837283a1504eb200cab1eba03650ea.zip
format payload if possible instead of returning "Box<Any>"
Diffstat (limited to 'src')
-rw-r--r--src/libstd/panicking.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index 6bb098310de..1f80fb6f738 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -440,12 +440,11 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
             PanicPayload { payload, msg, string: None }
         }
 
-
         fn fill(&mut self) -> Option<&mut String> {
-            if let Some(msg) = self.msg.take() {
+            if let Some(msg) = self.msg.cloned() {
                 Some(self.string.get_or_insert_with(|| {
                     let mut s = String::new();
-                    drop(s.write_fmt(*msg));
+                    drop(s.write_fmt(msg));
                     s
                 }))
             } else {
@@ -459,6 +458,10 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
             if let Some(string) = self.fill() {
                 let contents = mem::replace(string, String::new());
                 Box::into_raw(Box::new(contents))
+            } else if let Some(s) = self.payload.downcast_ref::<&str>() {
+                Box::into_raw(Box::new(s.to_owned()))
+            } else if let Some(s) = self.payload.downcast_ref::<String>() {
+                Box::into_raw(Box::new(s.clone()))
             } else {
                 // We can't go from &(Any+Send) to Box<Any+Send> so the payload is lost here
                 struct NoPayload;
@@ -467,7 +470,11 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
         }
 
         fn get(&mut self) -> &(Any + Send) {
-            self.payload
+            if let Some(s) = self.fill() {
+                s
+            } else {
+                self.payload
+            }
         }
     }
 }