diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-07-01 20:29:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 20:29:55 +0200 |
| commit | 61db24d15d9dff2576561abaad58b77aadb2764f (patch) | |
| tree | b09c4a1a836f44bccfcd5e5f7f8c32e280de4c97 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 221e2741c39515a5de6da42d8c76ee1e132c2c74 (diff) | |
| parent | bb00657d168e347ac04b5f90e8e77edc14a03050 (diff) | |
| download | rust-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 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
