@@ -34,13 +34,10 @@ use crate::panic::{Location, PanicInfo};
34
34
// never inline unless panic_immediate_abort to avoid code
35
35
// bloat at the call sites as much as possible
36
36
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
37
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
37
38
#[ track_caller]
38
39
#[ 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 ) -> ! {
44
41
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
45
42
// reduce size overhead. The format_args! macro uses str's Display trait to
46
43
// write expr, which calls Formatter::pad, which must accommodate string
@@ -52,15 +49,16 @@ pub fn panic(expr: &'static str) -> ! {
52
49
53
50
#[ inline]
54
51
#[ 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) ;
58
55
}
59
56
60
57
#[ inline]
61
58
#[ track_caller]
62
59
#[ 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 ) -> ! {
64
62
panic_fmt ( format_args ! ( "{}" , * x) ) ;
65
63
}
66
64
@@ -89,7 +87,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
89
87
#[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
90
88
#[ track_caller]
91
89
#[ 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 < ' _ > ) -> ! {
93
92
if cfg ! ( feature = "panic_immediate_abort" ) {
94
93
super :: intrinsics:: abort ( )
95
94
}
0 commit comments