diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 02cc0f9d77042..54b686ed4bc34 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1774,6 +1774,7 @@ const fn len_utf16(code: u32) -> usize { #[cfg_attr(bootstrap, rustc_const_stable(feature = "const_char_encode_utf8", since = "1.83.0"))] #[doc(hidden)] #[inline] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] { let len = len_utf8(code); match (len, &mut *dst) { @@ -1826,6 +1827,7 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] { )] #[doc(hidden)] #[inline] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] { let len = len_utf16(code); match (len, &mut *dst) { diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index d33a403cfda75..329e8bb6468ea 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2966,13 +2966,11 @@ pub(crate) macro const_eval_select { else $(#[$runtime_attr:meta])* $runtime:block ) => {{ - #[inline] // avoid the overhead of an extra fn call $(#[$runtime_attr])* fn runtime($($arg: $ty),*) $( -> $ret )? { $runtime } - #[inline] // prevent codegen on this function $(#[$compiletime_attr])* const fn compiletime($($arg: $ty),*) $( -> $ret )? { // Don't warn if one of the arguments is unused. diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 5a69dc0c7242b..0761b70ae0ebe 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1457,6 +1457,7 @@ pub const fn can_not_overflow(radix: u32, is_signed_ty: bool, digits: &[u8]) #[cfg_attr(feature = "panic_immediate_abort", inline)] #[cold] #[track_caller] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics const fn from_str_radix_panic(radix: u32) -> ! { const_panic!( "from_str_radix_int: must lie in the range `[2, 36]`", diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index f8f3962ce55ac..302ccda583f94 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -201,27 +201,16 @@ pub unsafe trait PanicPayload: crate::fmt::Display { #[unstable(feature = "panic_internals", issue = "none")] #[doc(hidden)] pub macro const_panic { - ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => {{ - // Wrap call to `const_eval_select` in a function so that we can - // add the `rustc_allow_const_fn_unstable`. This is okay to do - // because both variants will panic, just with different messages. - #[rustc_allow_const_fn_unstable(const_eval_select)] - #[inline(always)] - #[track_caller] - #[cfg_attr(bootstrap, rustc_const_stable(feature = "const_panic", since = "CURRENT_RUSTC_VERSION"))] - const fn do_panic($($arg: $ty),*) -> ! { - $crate::intrinsics::const_eval_select!( - @capture { $($arg: $ty),* } -> !: - if const #[track_caller] { - $crate::panic!($const_msg) - } else #[track_caller] { - $crate::panic!($runtime_msg) - } - ) - } - - do_panic($($val),*) - }}, + ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty = $val:expr),* $(,)?) => { + $crate::intrinsics::const_eval_select!( + @capture { $($arg: $ty = $val),* } -> !: + if const #[track_caller] { + $crate::panic!($const_msg) + } else #[track_caller] { + $crate::panic!($runtime_msg) + } + ) + }, // We support leaving away the `val` expressions for *all* arguments // (but not for *some* arguments, that's too tricky). ($const_msg:literal, $runtime_msg:literal, $($arg:ident : $ty:ty),* $(,)?) => { diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index aafa19c0dd3d3..9b5c122b2bdd5 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -31,6 +31,7 @@ where #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[track_caller] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics const fn slice_start_index_len_fail(index: usize, len: usize) -> ! { const_panic!( "slice start index is out of range for slice", @@ -43,6 +44,7 @@ const fn slice_start_index_len_fail(index: usize, len: usize) -> ! { #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[track_caller] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics const fn slice_end_index_len_fail(index: usize, len: usize) -> ! { const_panic!( "slice end index is out of range for slice", @@ -55,6 +57,7 @@ const fn slice_end_index_len_fail(index: usize, len: usize) -> ! { #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[track_caller] +#[rustc_allow_const_fn_unstable(const_eval_select)] // just used for panics const fn slice_index_order_fail(index: usize, end: usize) -> ! { const_panic!( "slice index start is larger than end",