Skip to content

Commit f090672

Browse files
Rollup merge of rust-lang#126732 - StackOverflowExcept1on:master, r=m-ou-se
Stabilize `PanicInfo::message()` and `PanicMessage` Resolves rust-lang#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: rust-lang#66745 (comment) r? libs-api
2 parents 4fff335 + 13ea648 commit f090672

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

core/src/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::any::Any;
1212
pub use self::location::Location;
1313
#[stable(feature = "panic_hooks", since = "1.10.0")]
1414
pub use self::panic_info::PanicInfo;
15-
#[unstable(feature = "panic_info_message", issue = "66745")]
15+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
1616
pub use self::panic_info::PanicMessage;
1717
#[stable(feature = "catch_unwind", since = "1.9.0")]
1818
pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};

core/src/panic/panic_info.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct PanicInfo<'a> {
2424
/// that were given to the `panic!()` macro.
2525
///
2626
/// See [`PanicInfo::message`].
27-
#[unstable(feature = "panic_info_message", issue = "66745")]
27+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
2828
pub struct PanicMessage<'a> {
2929
message: fmt::Arguments<'a>,
3030
}
@@ -57,7 +57,7 @@ impl<'a> PanicInfo<'a> {
5757
/// }
5858
/// ```
5959
#[must_use]
60-
#[unstable(feature = "panic_info_message", issue = "66745")]
60+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
6161
pub fn message(&self) -> PanicMessage<'_> {
6262
PanicMessage { message: self.message }
6363
}
@@ -164,7 +164,7 @@ impl<'a> PanicMessage<'a> {
164164
/// For most cases with placeholders, this function will return `None`.
165165
///
166166
/// See [`fmt::Arguments::as_str`] for details.
167-
#[unstable(feature = "panic_info_message", issue = "66745")]
167+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
168168
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "103900")]
169169
#[must_use]
170170
#[inline]
@@ -173,15 +173,15 @@ impl<'a> PanicMessage<'a> {
173173
}
174174
}
175175

176-
#[unstable(feature = "panic_info_message", issue = "66745")]
176+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
177177
impl Display for PanicMessage<'_> {
178178
#[inline]
179179
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
180180
formatter.write_fmt(self.message)
181181
}
182182
}
183183

184-
#[unstable(feature = "panic_info_message", issue = "66745")]
184+
#[stable(feature = "panic_info_message", since = "CURRENT_RUSTC_VERSION")]
185185
impl fmt::Debug for PanicMessage<'_> {
186186
#[inline]
187187
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {

std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@
339339
#![feature(maybe_uninit_slice)]
340340
#![feature(maybe_uninit_write_slice)]
341341
#![feature(panic_can_unwind)]
342-
#![feature(panic_info_message)]
343342
#![feature(panic_internals)]
344343
#![feature(pointer_is_aligned_to)]
345344
#![feature(portable_simd)]

0 commit comments

Comments
 (0)