about summary refs log tree commit diff
path: root/library/core/src/panic.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-07-01 20:29:55 +0200
committerGitHub <noreply@github.com>2024-07-01 20:29:55 +0200
commit61db24d15d9dff2576561abaad58b77aadb2764f (patch)
treeb09c4a1a836f44bccfcd5e5f7f8c32e280de4c97 /library/core/src/panic.rs
parent221e2741c39515a5de6da42d8c76ee1e132c2c74 (diff)
parentbb00657d168e347ac04b5f90e8e77edc14a03050 (diff)
downloadrust-61db24d15d9dff2576561abaad58b77aadb2764f.tar.gz
rust-61db24d15d9dff2576561abaad58b77aadb2764f.zip
Rollup merge of #126732 - StackOverflowExcept1on:master, r=m-ou-se
Stabilize `PanicInfo::message()` and `PanicMessage`

Resolves #66745

This stabilizes the [`PanicInfo::message()`](https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html#method.message) and [`PanicMessage`](https://doc.rust-lang.org/nightly/core/panic/struct.PanicMessage.html).

Demonstration of [custom panic handler](https://github.com/StackOverflowExcept1on/panicker):
```rust
#![no_std]
#![no_main]

extern crate libc;

#[no_mangle]
extern "C" fn main() -> libc::c_int {
    panic!("I just panic every time");
}

#[panic_handler]
fn my_panic(panic_info: &core::panic::PanicInfo) -> ! {
    use arrayvec::ArrayString;
    use core::fmt::Write;

    let message = panic_info.message();
    let location = panic_info.location().unwrap();

    let mut debug_msg = ArrayString::<1024>::new();
    let _ = write!(&mut debug_msg, "panicked with '{message}' at '{location}'");

    if debug_msg.try_push_str("\0").is_ok() {
        unsafe {
            libc::puts(debug_msg.as_ptr() as *const _);
        }
    }

    unsafe { libc::exit(libc::EXIT_FAILURE) }
}
```
```
$ cargo +stage1 run --release
panicked with 'I just panic every time' at 'src/main.rs:8:5'
```

- [x] FCP: https://github.com/rust-lang/rust/issues/66745#issuecomment-2198143725

r? libs-api
Diffstat (limited to 'library/core/src/panic.rs')
-rw-r--r--library/core/src/panic.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs
index 56ede02673c..37c338dd9b7 100644
--- a/library/core/src/panic.rs
+++ b/library/core/src/panic.rs
@@ -12,7 +12,7 @@ use crate::any::Any;
 pub use self::location::Location;
 #[stable(feature = "panic_hooks", since = "1.10.0")]
 pub use self::panic_info::PanicInfo;
-#[unstable(feature = "panic_info_message", issue = "66745")]
+#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
 pub use self::panic_info::PanicMessage;
 #[stable(feature = "catch_unwind", since = "1.9.0")]
 pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};