Skip to content

Commit a24d556

Browse files
committed
Add const-stability to panicking::panic_* fns
This allows us to use `panic!` and friends in a const-stable context within libcore.
1 parent d3f3004 commit a24d556

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#![feature(const_type_id)]
142142
#![feature(const_type_name)]
143143
#![feature(const_default_impls)]
144+
#![feature(core_panic)]
144145
#![feature(duration_consts_float)]
145146
#![feature(maybe_uninit_uninit_array)]
146147
#![feature(ptr_metadata)]

library/core/src/panicking.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub const fn panic(expr: &'static str) -> ! {
5151
#[inline]
5252
#[track_caller]
5353
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
54+
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
5455
pub const fn panic_str(expr: &str) -> ! {
5556
panic_display(&expr);
5657
}
@@ -59,6 +60,7 @@ pub const fn panic_str(expr: &str) -> ! {
5960
#[track_caller]
6061
#[lang = "panic_display"] // needed for const-evaluated panics
6162
#[rustc_do_not_const_check] // hooked by const-eval
63+
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
6264
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
6365
panic_fmt(format_args!("{}", *x));
6466
}
@@ -89,6 +91,7 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
8991
#[track_caller]
9092
#[lang = "panic_fmt"] // needed for const-evaluated panics
9193
#[rustc_do_not_const_check] // hooked by const-eval
94+
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
9295
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
9396
if cfg!(feature = "panic_immediate_abort") {
9497
super::intrinsics::abort()
@@ -109,6 +112,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
109112

110113
/// This function is used instead of panic_fmt in const eval.
111114
#[lang = "const_panic_fmt"]
115+
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
112116
pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
113117
if let Some(msg) = fmt.as_str() {
114118
panic_str(msg);

0 commit comments

Comments
 (0)