3131use crate :: fmt;
3232use crate :: panic:: { Location , PanicInfo } ;
3333
34- #[ cfg( bootstrap) ]
35- #[ cold]
36- // never inline unless panic_immediate_abort to avoid code
37- // bloat at the call sites as much as possible
38- #[ cfg_attr( not( feature="panic_immediate_abort" ) , inline( never) ) ]
39- #[ lang = "panic" ]
40- pub fn panic ( expr_file_line_col : & ( & ' static str , & ' static str , u32 , u32 ) ) -> ! {
41- if cfg ! ( feature = "panic_immediate_abort" ) {
42- unsafe { super :: intrinsics:: abort ( ) }
43- }
44-
45- // Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
46- // reduce size overhead. The format_args! macro uses str's Display trait to
47- // write expr, which calls Formatter::pad, which must accommodate string
48- // truncation and padding (even though none is used here). Using
49- // Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
50- // output binary, saving up to a few kilobytes.
51- let ( expr, file, line, col) = * expr_file_line_col;
52- panic_fmt ( fmt:: Arguments :: new_v1 ( & [ expr] , & [ ] ) , & ( file, line, col) )
53- }
54-
55- #[ cfg( not( bootstrap) ) ]
5634#[ cold]
5735// never inline unless panic_immediate_abort to avoid code
5836// bloat at the call sites as much as possible
@@ -72,21 +50,6 @@ pub fn panic(expr: &str, location: &Location<'_>) -> ! {
7250 panic_fmt ( fmt:: Arguments :: new_v1 ( & [ expr] , & [ ] ) , location)
7351}
7452
75- #[ cfg( bootstrap) ]
76- #[ cold]
77- #[ cfg_attr( not( feature="panic_immediate_abort" ) , inline( never) ) ]
78- #[ lang = "panic_bounds_check" ]
79- fn panic_bounds_check ( file_line_col : & ( & ' static str , u32 , u32 ) ,
80- index : usize , len : usize ) -> ! {
81- if cfg ! ( feature = "panic_immediate_abort" ) {
82- unsafe { super :: intrinsics:: abort ( ) }
83- }
84-
85- panic_fmt ( format_args ! ( "index out of bounds: the len is {} but the index is {}" ,
86- len, index) , file_line_col)
87- }
88-
89- #[ cfg( not( bootstrap) ) ]
9053#[ cold]
9154#[ cfg_attr( not( feature="panic_immediate_abort" ) , inline( never) ) ]
9255#[ lang = "panic_bounds_check" ]
@@ -101,28 +64,6 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
10164 )
10265}
10366
104- #[ cfg( bootstrap) ]
105- #[ cold]
106- #[ cfg_attr( not( feature="panic_immediate_abort" ) , inline( never) ) ]
107- #[ cfg_attr( feature="panic_immediate_abort" , inline) ]
108- pub fn panic_fmt ( fmt : fmt:: Arguments < ' _ > , file_line_col : & ( & ' static str , u32 , u32 ) ) -> ! {
109- if cfg ! ( feature = "panic_immediate_abort" ) {
110- unsafe { super :: intrinsics:: abort ( ) }
111- }
112-
113- // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
114- extern "Rust" {
115- #[ lang = "panic_impl" ]
116- fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
117- }
118-
119- let ( file, line, col) = * file_line_col;
120- let location = Location :: internal_constructor ( file, line, col) ;
121- let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , & location) ;
122- unsafe { panic_impl ( & pi) }
123- }
124-
125- #[ cfg( not( bootstrap) ) ]
12667#[ cold]
12768#[ cfg_attr( not( feature="panic_immediate_abort" ) , inline( never) ) ]
12869#[ cfg_attr( feature="panic_immediate_abort" , inline) ]
0 commit comments