Skip to content

Commit 9e07477

Browse files
committed
Auto merge of rust-lang#90273 - nbdd0121:const, r=fee1-dead
Clean up special function const checks Mark them as const and `#[rustc_do_not_const_check]` instead of hard-coding them in const-eval checks. r? `@oli-obk` `@rustbot` label A-const-eval T-compiler
2 parents a349389 + 1236806 commit 9e07477

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#![feature(const_discriminant)]
108108
#![feature(const_float_bits_conv)]
109109
#![feature(const_float_classify)]
110+
#![feature(const_fmt_arguments_new)]
110111
#![feature(const_heap)]
111112
#![feature(const_inherent_unchecked_arith)]
112113
#![feature(const_int_unchecked_arith)]

core/src/panicking.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ use crate::panic::{Location, PanicInfo};
3434
// never inline unless panic_immediate_abort to avoid code
3535
// bloat at the call sites as much as possible
3636
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
37+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
3738
#[track_caller]
3839
#[lang = "panic"] // needed by codegen for panic on overflow and other `Assert` MIR terminators
39-
pub fn panic(expr: &'static str) -> ! {
40-
if cfg!(feature = "panic_immediate_abort") {
41-
super::intrinsics::abort()
42-
}
43-
40+
pub const fn panic(expr: &'static str) -> ! {
4441
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
4542
// reduce size overhead. The format_args! macro uses str's Display trait to
4643
// write expr, which calls Formatter::pad, which must accommodate string
@@ -52,15 +49,16 @@ pub fn panic(expr: &'static str) -> ! {
5249

5350
#[inline]
5451
#[track_caller]
55-
#[lang = "panic_str"] // needed for const-evaluated panics
56-
pub fn panic_str(expr: &str) -> ! {
57-
panic_fmt(format_args!("{}", expr));
52+
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
53+
pub const fn panic_str(expr: &str) -> ! {
54+
panic_display(&expr);
5855
}
5956

6057
#[inline]
6158
#[track_caller]
6259
#[lang = "panic_display"] // needed for const-evaluated panics
63-
pub fn panic_display<T: fmt::Display>(x: &T) -> ! {
60+
#[rustc_do_not_const_check] // hooked by const-eval
61+
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
6462
panic_fmt(format_args!("{}", *x));
6563
}
6664

@@ -89,7 +87,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
8987
#[cfg_attr(feature = "panic_immediate_abort", inline)]
9088
#[track_caller]
9189
#[lang = "panic_fmt"] // needed for const-evaluated panics
92-
pub fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
90+
#[rustc_do_not_const_check] // hooked by const-eval
91+
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
9392
if cfg!(feature = "panic_immediate_abort") {
9493
super::intrinsics::abort()
9594
}

std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
#![feature(const_cstr_unchecked)]
258258
#![feature(const_fn_floating_point_arithmetic)]
259259
#![feature(const_fn_fn_ptr_basics)]
260+
#![feature(const_fn_trait_bound)]
260261
#![feature(const_format_args)]
261262
#![feature(const_io_structs)]
262263
#![feature(const_ip)]

std/src/panicking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
512512
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
513513
#[cold]
514514
#[track_caller]
515-
pub fn begin_panic<M: Any + Send>(msg: M) -> ! {
515+
#[rustc_do_not_const_check] // hooked by const-eval
516+
pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
516517
if cfg!(feature = "panic_immediate_abort") {
517518
intrinsics::abort()
518519
}

0 commit comments

Comments
 (0)