@@ -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 }
0 commit comments