Add const-stability to panicking::panic_*
fns
This allows us to use `panic!` and friends in a const-stable context within libcore.
This commit is contained in:
parent
390bb3406d
commit
f52eb4ca8b
1 changed files with 4 additions and 0 deletions
|
@ -51,6 +51,7 @@ pub const fn panic(expr: &'static str) -> ! {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
|
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
|
||||||
|
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
||||||
pub const fn panic_str(expr: &str) -> ! {
|
pub const fn panic_str(expr: &str) -> ! {
|
||||||
panic_display(&expr);
|
panic_display(&expr);
|
||||||
}
|
}
|
||||||
|
@ -59,6 +60,7 @@ pub const fn panic_str(expr: &str) -> ! {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[lang = "panic_display"] // needed for const-evaluated panics
|
#[lang = "panic_display"] // needed for const-evaluated panics
|
||||||
#[rustc_do_not_const_check] // hooked by const-eval
|
#[rustc_do_not_const_check] // hooked by const-eval
|
||||||
|
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
||||||
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
|
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
|
||||||
panic_fmt(format_args!("{}", *x));
|
panic_fmt(format_args!("{}", *x));
|
||||||
}
|
}
|
||||||
|
@ -89,6 +91,7 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[lang = "panic_fmt"] // needed for const-evaluated panics
|
#[lang = "panic_fmt"] // needed for const-evaluated panics
|
||||||
#[rustc_do_not_const_check] // hooked by const-eval
|
#[rustc_do_not_const_check] // hooked by const-eval
|
||||||
|
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
||||||
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
||||||
if cfg!(feature = "panic_immediate_abort") {
|
if cfg!(feature = "panic_immediate_abort") {
|
||||||
super::intrinsics::abort()
|
super::intrinsics::abort()
|
||||||
|
@ -109,6 +112,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
||||||
|
|
||||||
/// This function is used instead of panic_fmt in const eval.
|
/// This function is used instead of panic_fmt in const eval.
|
||||||
#[lang = "const_panic_fmt"]
|
#[lang = "const_panic_fmt"]
|
||||||
|
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
||||||
pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
||||||
if let Some(msg) = fmt.as_str() {
|
if let Some(msg) = fmt.as_str() {
|
||||||
panic_str(msg);
|
panic_str(msg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue