Skip to content

Commit 9d7a01e

Browse files
committed
cleanup and formatting
1 parent fae2e3f commit 9d7a01e

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

library/core/src/panic/panic_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a> PanicInfo<'a> {
6666
}
6767

6868
#[unstable(feature = "error_in_panic", issue = "none")]
69-
/// The lower-level source of this panic, if any.
69+
/// The [`Error`] that caused this panic, if known.
7070
pub fn source(&self) -> Option<&(dyn Error + 'static)> {
7171
self.source
7272
}

library/core/src/panicking.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,10 @@ const _: () = assert!(cfg!(panic = "abort"), "panic_immediate_abort requires -C
5151
#[rustc_do_not_const_check] // hooked by const-eval
5252
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
5353
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
54-
//panic_source(fmt, None)
5554
if cfg!(feature = "panic_immediate_abort") {
5655
super::intrinsics::abort()
5756
}
5857

59-
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
60-
// that gets resolved to the `#[panic_handler]` function.
61-
extern "Rust" {
62-
#[lang = "panic_impl"]
63-
fn panic_impl(pi: &PanicInfo<'_>) -> !;
64-
}
65-
6658
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), None, true);
6759

6860
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
@@ -82,19 +74,19 @@ pub const fn panic_source(fmt: fmt::Arguments<'_>, source: &(dyn Error + 'static
8274
super::intrinsics::abort()
8375
}
8476

85-
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
86-
// that gets resolved to the `#[panic_handler]` function.
87-
extern "Rust" {
88-
#[lang = "panic_impl"]
89-
fn panic_impl(pi: &PanicInfo<'_>) -> !;
90-
}
91-
9277
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), Some(source), true);
9378

9479
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
9580
unsafe { panic_impl(&pi) }
9681
}
9782

83+
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
84+
// that gets resolved to the `#[panic_handler]` function.
85+
extern "Rust" {
86+
#[lang = "panic_impl"]
87+
fn panic_impl(pi: &PanicInfo<'_>) -> !;
88+
}
89+
9890
/// Like `panic_fmt`, but for non-unwinding panics.
9991
///
10092
/// Has to be a separate function so that it can carry the `rustc_nounwind` attribute.

library/std/src/panicking.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn default_hook(info: &PanicInfo<'_>) {
261261
let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}");
262262
if let Some(source) = info.source() {
263263
let report = Report::new(source).pretty(true);
264-
let _ = writeln!(err, "Source: {report}");
264+
let _ = writeln!(err, "\nSource: {report}\n");
265265
}
266266
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
267267

@@ -578,23 +578,22 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
578578
}
579579

580580
let loc = info.location().unwrap(); // The current implementation always returns Some
581-
let source = info.source();
582581
let msg = info.message().unwrap(); // The current implementation always returns Some
583582
crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
584583
if let Some(msg) = msg.as_str() {
585584
rust_panic_with_hook(
586585
&mut StrPanicPayload(msg),
587586
info.message(),
588587
loc,
589-
source,
588+
info.source(),
590589
info.can_unwind(),
591590
);
592591
} else {
593592
rust_panic_with_hook(
594593
&mut PanicPayload::new(msg),
595594
info.message(),
596595
loc,
597-
source,
596+
info.source(),
598597
info.can_unwind(),
599598
);
600599
}

0 commit comments

Comments
 (0)