Skip to content

Commit f15c816

Browse files
committed
Make PanicInfo::message available for std::panic! with a formatting string.
This enables PanicInfo’s Display impl to show the panic message in those cases.
1 parent 0e60287 commit f15c816

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/libcore/panic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ impl<'a> fmt::Display for PanicInfo<'a> {
130130
}
131131
// NOTE: we cannot use downcast_ref::<String>() here
132132
// since String is not available in libcore!
133-
// A String payload and no message is what we’d get from `std::panic!`
134-
// called with multiple arguments.
133+
// The payload is a String when `std::panic!` is called with multiple arguments,
134+
// but in that case the message is also available.
135135

136136
self.location.fmt(formatter)
137137
}

src/libstd/panicking.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments,
344344

345345
let mut s = String::new();
346346
let _ = s.write_fmt(*msg);
347-
begin_panic(s, file_line_col)
347+
rust_panic_with_hook(Box::new(s), Some(msg), file_line_col)
348348
}
349349

350350
/// This is the entry point of panicking for panic!() and assert!().
@@ -360,7 +360,7 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
360360
// be performed in the parent of this thread instead of the thread that's
361361
// panicking.
362362

363-
rust_panic_with_hook(Box::new(msg), file_line_col)
363+
rust_panic_with_hook(Box::new(msg), None, file_line_col)
364364
}
365365

366366
/// Executes the primary logic for a panic, including checking for recursive
@@ -371,7 +371,8 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
371371
/// run panic hooks, and then delegate to the actual implementation of panics.
372372
#[inline(never)]
373373
#[cold]
374-
fn rust_panic_with_hook(msg: Box<Any + Send>,
374+
fn rust_panic_with_hook(payload: Box<Any + Send>,
375+
message: Option<&fmt::Arguments>,
375376
file_line_col: &(&'static str, u32, u32)) -> ! {
376377
let (file, line, col) = *file_line_col;
377378

@@ -390,8 +391,8 @@ fn rust_panic_with_hook(msg: Box<Any + Send>,
390391

391392
unsafe {
392393
let info = PanicInfo::internal_constructor(
393-
&*msg,
394-
None,
394+
&*payload,
395+
message,
395396
Location::internal_constructor(file, line, col),
396397
);
397398
HOOK_LOCK.read();
@@ -412,7 +413,7 @@ fn rust_panic_with_hook(msg: Box<Any + Send>,
412413
unsafe { intrinsics::abort() }
413414
}
414415

415-
rust_panic(msg)
416+
rust_panic(payload)
416417
}
417418

418419
/// Shim around rust_panic. Called by resume_unwind.

0 commit comments

Comments
 (0)