Skip to content

Commit fae2e3f

Browse files
committed
cleanup FIXMEs
1 parent 0bfd9c5 commit fae2e3f

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
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-
/// FIXME
69+
/// The lower-level source of this panic, if any.
7070
pub fn source(&self) -> Option<&(dyn Error + 'static)> {
7171
self.source
7272
}

library/core/src/panicking.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,22 @@ 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)
54+
//panic_source(fmt, None)
55+
if cfg!(feature = "panic_immediate_abort") {
56+
super::intrinsics::abort()
57+
}
58+
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+
66+
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), None, true);
67+
68+
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
69+
unsafe { panic_impl(&pi) }
5570
}
5671

5772
#[cold]
@@ -62,7 +77,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
6277
#[track_caller]
6378
#[rustc_do_not_const_check] // hooked by const-eval
6479
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
65-
pub const fn panic_source(fmt: fmt::Arguments<'_>, source: Option<&(dyn Error + 'static)>) -> ! {
80+
pub const fn panic_source(fmt: fmt::Arguments<'_>, source: &(dyn Error + 'static)) -> ! {
6681
if cfg!(feature = "panic_immediate_abort") {
6782
super::intrinsics::abort()
6883
}
@@ -74,7 +89,7 @@ pub const fn panic_source(fmt: fmt::Arguments<'_>, source: Option<&(dyn Error +
7489
fn panic_impl(pi: &PanicInfo<'_>) -> !;
7590
}
7691

77-
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), source, true);
92+
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), Some(source), true);
7893

7994
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
8095
unsafe { panic_impl(&pi) }

src/test/ui/error-trait/error-in-panic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ impl error::Error for SourceError {
4444
}
4545

4646
fn main() {
47-
std::env::set_var("RUST_BACKTRACE", "full");
4847
let source_error = SourceError {};
4948
let source = MyErr {super_source: source_error};
50-
//FIXME make the function do the Some wrapping for us
51-
panic_source(format_args!("here's my panic error message"), Some(&source));
52-
49+
panic_source(format_args!("here's my panic error message"), &source);
5350
}
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
thread 'main' panicked at 'here's my panic error message', $DIR/error-in-panic.rs:51:5
1+
thread 'main' panicked at 'here's my panic error message', $DIR/error-in-panic.rs:49:5
22
Source: my source error message
33

44
Caused by:
55
my source's source error message
6-
stack backtrace:
7-
0: 0x10347e5cc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h739002e9033ecbde
8-
1: 0x1034c1ef4 - core::fmt::write::h7ee3c88f1a3812c3
9-
2: 0x103467ad8 - std::io::Write::write_fmt::h46e675c7a43a1dc6
10-
3: 0x10347e494 - std::sys_common::backtrace::print::h2db63c69899aa986
11-
4: 0x103441588 - std::panicking::default_hook::{{closure}}::hbf1cbfed6089b966
12-
5: 0x103441348 - std::panicking::default_hook::h394fc36f8066489c
13-
6: 0x103441a3c - std::panicking::rust_panic_with_hook::h022616bb2ba4e178
14-
7: 0x10344907c - std::panicking::begin_panic_handler::{{closure}}::h3128246bc073fcbe
15-
8: 0x103448fdc - std::sys_common::backtrace::__rust_end_short_backtrace::hbb524939a68ed8b5
16-
9: 0x103441660 - _rust_begin_unwind
17-
10: 0x1034dd910 - core::panicking::panic_source::hf14287b3ee2e7392
18-
11: 0x102aeb728 - error_in_panic::main::hf4bbb2ae489ce4fd
19-
12: 0x102aeb404 - core::ops::function::FnOnce::call_once::h0f54538c8c239b20
20-
13: 0x102aeafd8 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2b8f58dd23d62fa6
21-
14: 0x102aeb074 - std::rt::lang_start::{{closure}}::h6d7fe7ddaa109f16
22-
15: 0x10344478c - std::panicking::try::h0286e30fd7b2d786
23-
16: 0x103452248 - std::rt::lang_start_internal::hc2ec5a7105141124
24-
17: 0x102aeb048 - std::rt::lang_start::h8ea75b901d46518a
25-
18: 0x102aeb7f0 - _main
6+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)