format payload if possible instead of returning "Box<Any>"
This commit is contained in:
@@ -440,12 +440,11 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
|
|||||||
PanicPayload { payload, msg, string: None }
|
PanicPayload { payload, msg, string: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn fill(&mut self) -> Option<&mut String> {
|
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(|| {
|
Some(self.string.get_or_insert_with(|| {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
drop(s.write_fmt(*msg));
|
drop(s.write_fmt(msg));
|
||||||
s
|
s
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
@@ -459,6 +458,10 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
|
|||||||
if let Some(string) = self.fill() {
|
if let Some(string) = self.fill() {
|
||||||
let contents = mem::replace(string, String::new());
|
let contents = mem::replace(string, String::new());
|
||||||
Box::into_raw(Box::new(contents))
|
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 {
|
} else {
|
||||||
// We can't go from &(Any+Send) to Box<Any+Send> so the payload is lost here
|
// We can't go from &(Any+Send) to Box<Any+Send> so the payload is lost here
|
||||||
struct NoPayload;
|
struct NoPayload;
|
||||||
@@ -467,10 +470,14 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get(&mut self) -> &(Any + Send) {
|
fn get(&mut self) -> &(Any + Send) {
|
||||||
|
if let Some(s) = self.fill() {
|
||||||
|
s
|
||||||
|
} else {
|
||||||
self.payload
|
self.payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This is the entry point of panicking for panic!() and assert!().
|
/// This is the entry point of panicking for panic!() and assert!().
|
||||||
#[unstable(feature = "libstd_sys_internals",
|
#[unstable(feature = "libstd_sys_internals",
|
||||||
|
|||||||
Reference in New Issue
Block a user