3232use crate :: fmt;
3333use crate :: panic:: { Location , PanicInfo } ;
3434
35+ /// The underlying implementation of libcore's `panic!` macro when no formatting is used.
3536#[ cold]
3637// never inline unless panic_immediate_abort to avoid code
3738// bloat at the call sites as much as possible
@@ -49,7 +50,10 @@ pub fn panic(expr: &str) -> ! {
4950 // truncation and padding (even though none is used here). Using
5051 // Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
5152 // output binary, saving up to a few kilobytes.
52- panic_fmt ( fmt:: Arguments :: new_v1 ( & [ expr] , & [ ] ) , Location :: caller ( ) )
53+ #[ cfg( not( bootstrap) ) ]
54+ panic_fmt ( fmt:: Arguments :: new_v1 ( & [ expr] , & [ ] ) ) ;
55+ #[ cfg( bootstrap) ]
56+ panic_fmt ( fmt:: Arguments :: new_v1 ( & [ expr] , & [ ] ) , Location :: caller ( ) ) ;
5357}
5458
5559#[ cfg( not( bootstrap) ) ]
@@ -62,13 +66,11 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
6266 unsafe { super :: intrinsics:: abort ( ) }
6367 }
6468
65- panic_fmt (
66- format_args ! ( "index out of bounds: the len is {} but the index is {}" , len, index) ,
67- Location :: caller ( ) ,
68- )
69+ panic ! ( "index out of bounds: the len is {} but the index is {}" , len, index)
6970}
7071
71- // For bootstrap, we need a variant with the old argument order.
72+ // For bootstrap, we need a variant with the old argument order, and a corresponding
73+ // `panic_fmt`.
7274#[ cfg( bootstrap) ]
7375#[ cold]
7476#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
@@ -84,10 +86,12 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
8486 )
8587}
8688
89+ /// The underlying implementation of libcore's `panic!` macro when formatting is used.
8790#[ cold]
8891#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
8992#[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
90- pub fn panic_fmt ( fmt : fmt:: Arguments < ' _ > , location : & Location < ' _ > ) -> ! {
93+ #[ cfg_attr( not( bootstrap) , track_caller) ]
94+ pub fn panic_fmt ( fmt : fmt:: Arguments < ' _ > , #[ cfg( bootstrap) ] location : & Location < ' _ > ) -> ! {
9195 if cfg ! ( feature = "panic_immediate_abort" ) {
9296 unsafe { super :: intrinsics:: abort ( ) }
9397 }
@@ -99,6 +103,10 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
99103 fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
100104 }
101105
106+ #[ cfg( bootstrap) ]
102107 let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , location) ;
108+ #[ cfg( not( bootstrap) ) ]
109+ let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) ) ;
110+
103111 unsafe { panic_impl ( & pi) }
104112}
0 commit comments