32
32
use crate :: fmt;
33
33
use crate :: panic:: { Location , PanicInfo } ;
34
34
35
+ /// The underlying implementation of libcore's `panic!` macro when no formatting is used.
35
36
#[ cold]
36
37
// never inline unless panic_immediate_abort to avoid code
37
38
// bloat at the call sites as much as possible
@@ -49,7 +50,10 @@ pub fn panic(expr: &str) -> ! {
49
50
// truncation and padding (even though none is used here). Using
50
51
// Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
51
52
// 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 ( ) ) ;
53
57
}
54
58
55
59
#[ cfg( not( bootstrap) ) ]
@@ -62,13 +66,11 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
62
66
unsafe { super :: intrinsics:: abort ( ) }
63
67
}
64
68
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)
69
70
}
70
71
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`.
72
74
#[ cfg( bootstrap) ]
73
75
#[ cold]
74
76
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
@@ -84,10 +86,12 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
84
86
)
85
87
}
86
88
89
+ /// The underlying implementation of libcore's `panic!` macro when formatting is used.
87
90
#[ cold]
88
91
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
89
92
#[ 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 < ' _ > ) -> ! {
91
95
if cfg ! ( feature = "panic_immediate_abort" ) {
92
96
unsafe { super :: intrinsics:: abort ( ) }
93
97
}
@@ -99,6 +103,10 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
99
103
fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
100
104
}
101
105
106
+ #[ cfg( bootstrap) ]
102
107
let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , location) ;
108
+ #[ cfg( not( bootstrap) ) ]
109
+ let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) ) ;
110
+
103
111
unsafe { panic_impl ( & pi) }
104
112
}
0 commit comments