@@ -313,17 +313,15 @@ pub fn panicking() -> bool {
313
313
#[ cold]
314
314
// If panic_immediate_abort, inline the abort call,
315
315
// otherwise avoid inlining because of it is cold path.
316
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , track_caller) ]
316
317
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
317
318
#[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
318
- pub fn begin_panic_fmt ( msg : & fmt:: Arguments < ' _ > , file_line_col : & ( & ' static str , u32 , u32 ) ) -> ! {
319
+ pub fn begin_panic_fmt ( msg : & fmt:: Arguments < ' _ > ) -> ! {
319
320
if cfg ! ( feature = "panic_immediate_abort" ) {
320
321
unsafe { intrinsics:: abort ( ) }
321
322
}
322
323
323
- // Just package everything into a `PanicInfo` and continue like libcore panics.
324
- let ( file, line, col) = * file_line_col;
325
- let location = Location :: internal_constructor ( file, line, col) ;
326
- let info = PanicInfo :: internal_constructor ( Some ( msg) , & location) ;
324
+ let info = PanicInfo :: internal_constructor ( Some ( msg) , Location :: caller ( ) ) ;
327
325
begin_panic_handler ( & info)
328
326
}
329
327
@@ -356,6 +354,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
356
354
357
355
unsafe impl < ' a > BoxMeUp for PanicPayload < ' a > {
358
356
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
357
+ // We do two allocations here, unfortunately. But (a) they're required with the current
358
+ // scheme, and (b) we don't handle panic + OOM properly anyway (see comment in
359
+ // begin_panic below).
359
360
let contents = mem:: take ( self . fill ( ) ) ;
360
361
Box :: into_raw ( Box :: new ( contents) )
361
362
}
@@ -365,15 +366,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
365
366
}
366
367
}
367
368
368
- // We do two allocations here, unfortunately. But (a) they're
369
- // required with the current scheme, and (b) we don't handle
370
- // panic + OOM properly anyway (see comment in begin_panic
371
- // below).
372
-
373
369
let loc = info. location ( ) . unwrap ( ) ; // The current implementation always returns Some
374
370
let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
375
- let file_line_col = ( loc. file ( ) , loc. line ( ) , loc. column ( ) ) ;
376
- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , info. message ( ) , & file_line_col) ;
371
+ rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , info. message ( ) , loc) ;
377
372
}
378
373
379
374
/// This is the entry point of panicking for the non-format-string variants of
@@ -386,19 +381,13 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
386
381
// bloat at the call sites as much as possible
387
382
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
388
383
#[ cold]
389
- pub fn begin_panic < M : Any + Send > ( msg : M , file_line_col : & ( & ' static str , u32 , u32 ) ) -> ! {
384
+ #[ track_caller]
385
+ pub fn begin_panic < M : Any + Send > ( msg : M , #[ cfg( bootstrap) ] _: & ( & str , u32 , u32 ) ) -> ! {
390
386
if cfg ! ( feature = "panic_immediate_abort" ) {
391
387
unsafe { intrinsics:: abort ( ) }
392
388
}
393
389
394
- // Note that this should be the only allocation performed in this code path.
395
- // Currently this means that panic!() on OOM will invoke this code path,
396
- // but then again we're not really ready for panic on OOM anyway. If
397
- // we do start doing this, then we should propagate this allocation to
398
- // be performed in the parent of this thread instead of the thread that's
399
- // panicking.
400
-
401
- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , file_line_col) ;
390
+ rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , Location :: caller ( ) ) ;
402
391
403
392
struct PanicPayload < A > {
404
393
inner : Option < A > ,
@@ -412,6 +401,11 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
412
401
413
402
unsafe impl < A : Send + ' static > BoxMeUp for PanicPayload < A > {
414
403
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
404
+ // Note that this should be the only allocation performed in this code path. Currently
405
+ // this means that panic!() on OOM will invoke this code path, but then again we're not
406
+ // really ready for panic on OOM anyway. If we do start doing this, then we should
407
+ // propagate this allocation to be performed in the parent of this thread instead of the
408
+ // thread that's panicking.
415
409
let data = match self . inner . take ( ) {
416
410
Some ( a) => Box :: new ( a) as Box < dyn Any + Send > ,
417
411
None => process:: abort ( ) ,
@@ -436,10 +430,8 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
436
430
fn rust_panic_with_hook (
437
431
payload : & mut dyn BoxMeUp ,
438
432
message : Option < & fmt:: Arguments < ' _ > > ,
439
- file_line_col : & ( & str , u32 , u32 ) ,
433
+ location : & Location < ' _ > ,
440
434
) -> ! {
441
- let ( file, line, col) = * file_line_col;
442
-
443
435
let panics = update_panic_count ( 1 ) ;
444
436
445
437
// If this is the third nested call (e.g., panics == 2, this is 0-indexed),
@@ -456,8 +448,7 @@ fn rust_panic_with_hook(
456
448
}
457
449
458
450
unsafe {
459
- let location = Location :: internal_constructor ( file, line, col) ;
460
- let mut info = PanicInfo :: internal_constructor ( message, & location) ;
451
+ let mut info = PanicInfo :: internal_constructor ( message, location) ;
461
452
HOOK_LOCK . read ( ) ;
462
453
match HOOK {
463
454
// Some platforms (like wasm) know that printing to stderr won't ever actually
0 commit comments