10
10
#![ deny( unsafe_op_in_unsafe_fn) ]
11
11
12
12
use crate :: panic:: BacktraceStyle ;
13
- use core:: panic:: { BoxMeUp , Location , PanicInfo } ;
13
+ use core:: panic:: { Location , PanicInfo , PanicPayload } ;
14
14
15
15
use crate :: any:: Any ;
16
16
use crate :: fmt;
@@ -47,9 +47,9 @@ extern "C" {
47
47
}
48
48
49
49
extern "Rust" {
50
- /// `BoxMeUp ` lazily performs allocation only when needed (this avoids
50
+ /// `PanicPayload ` lazily performs allocation only when needed (this avoids
51
51
/// allocations when using the "abort" panic runtime).
52
- fn __rust_start_panic ( payload : & mut dyn BoxMeUp ) -> u32 ;
52
+ fn __rust_start_panic ( payload : & mut dyn PanicPayload ) -> u32 ;
53
53
}
54
54
55
55
/// This function is called by the panic runtime if FFI code catches a Rust
@@ -543,14 +543,14 @@ pub fn panicking() -> bool {
543
543
#[ cfg( not( test) ) ]
544
544
#[ panic_handler]
545
545
pub fn begin_panic_handler ( info : & PanicInfo < ' _ > ) -> ! {
546
- struct PanicPayload < ' a > {
546
+ struct FormatStringPayload < ' a > {
547
547
inner : & ' a fmt:: Arguments < ' a > ,
548
548
string : Option < String > ,
549
549
}
550
550
551
- impl < ' a > PanicPayload < ' a > {
552
- fn new ( inner : & ' a fmt:: Arguments < ' a > ) -> PanicPayload < ' a > {
553
- PanicPayload { inner, string : None }
551
+ impl < ' a > FormatStringPayload < ' a > {
552
+ fn new ( inner : & ' a fmt:: Arguments < ' a > ) -> Self {
553
+ Self { inner, string : None }
554
554
}
555
555
556
556
fn fill ( & mut self ) -> & mut String {
@@ -566,7 +566,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
566
566
}
567
567
}
568
568
569
- unsafe impl < ' a > BoxMeUp for PanicPayload < ' a > {
569
+ unsafe impl < ' a > PanicPayload for FormatStringPayload < ' a > {
570
570
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
571
571
// We do two allocations here, unfortunately. But (a) they're required with the current
572
572
// scheme, and (b) we don't handle panic + OOM properly anyway (see comment in
@@ -580,9 +580,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
580
580
}
581
581
}
582
582
583
- struct StrPanicPayload ( & ' static str ) ;
583
+ struct StaticStrPayload ( & ' static str ) ;
584
584
585
- unsafe impl BoxMeUp for StrPanicPayload {
585
+ unsafe impl PanicPayload for StaticStrPayload {
586
586
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
587
587
Box :: into_raw ( Box :: new ( self . 0 ) )
588
588
}
@@ -599,15 +599,15 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
599
599
// `rust_panic_with_hook` construct a new `PanicInfo`?
600
600
if let Some ( msg) = msg. as_str ( ) {
601
601
rust_panic_with_hook (
602
- & mut StrPanicPayload ( msg) ,
602
+ & mut StaticStrPayload ( msg) ,
603
603
info. message ( ) ,
604
604
loc,
605
605
info. can_unwind ( ) ,
606
606
info. force_no_backtrace ( ) ,
607
607
) ;
608
608
} else {
609
609
rust_panic_with_hook (
610
- & mut PanicPayload :: new ( msg) ,
610
+ & mut FormatStringPayload :: new ( msg) ,
611
611
info. message ( ) ,
612
612
loc,
613
613
info. can_unwind ( ) ,
@@ -637,25 +637,25 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
637
637
let loc = Location :: caller ( ) ;
638
638
return crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
639
639
rust_panic_with_hook (
640
- & mut PanicPayload :: new ( msg) ,
640
+ & mut Payload :: new ( msg) ,
641
641
None ,
642
642
loc,
643
643
/* can_unwind */ true ,
644
644
/* force_no_backtrace */ false ,
645
645
)
646
646
} ) ;
647
647
648
- struct PanicPayload < A > {
648
+ struct Payload < A > {
649
649
inner : Option < A > ,
650
650
}
651
651
652
- impl < A : Send + ' static > PanicPayload < A > {
653
- fn new ( inner : A ) -> PanicPayload < A > {
654
- PanicPayload { inner : Some ( inner) }
652
+ impl < A : Send + ' static > Payload < A > {
653
+ fn new ( inner : A ) -> Payload < A > {
654
+ Payload { inner : Some ( inner) }
655
655
}
656
656
}
657
657
658
- unsafe impl < A : Send + ' static > BoxMeUp for PanicPayload < A > {
658
+ unsafe impl < A : Send + ' static > PanicPayload for Payload < A > {
659
659
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
660
660
// Note that this should be the only allocation performed in this code path. Currently
661
661
// this means that panic!() on OOM will invoke this code path, but then again we're not
@@ -684,7 +684,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
684
684
/// panics, panic hooks, and finally dispatching to the panic runtime to either
685
685
/// abort or unwind.
686
686
fn rust_panic_with_hook (
687
- payload : & mut dyn BoxMeUp ,
687
+ payload : & mut dyn PanicPayload ,
688
688
message : Option < & fmt:: Arguments < ' _ > > ,
689
689
location : & Location < ' _ > ,
690
690
can_unwind : bool ,
@@ -760,7 +760,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
760
760
761
761
struct RewrapBox ( Box < dyn Any + Send > ) ;
762
762
763
- unsafe impl BoxMeUp for RewrapBox {
763
+ unsafe impl PanicPayload for RewrapBox {
764
764
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
765
765
Box :: into_raw ( mem:: replace ( & mut self . 0 , Box :: new ( ( ) ) ) )
766
766
}
@@ -777,7 +777,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
777
777
/// yer breakpoints.
778
778
#[ inline( never) ]
779
779
#[ cfg_attr( not( test) , rustc_std_internal_symbol) ]
780
- fn rust_panic ( msg : & mut dyn BoxMeUp ) -> ! {
780
+ fn rust_panic ( msg : & mut dyn PanicPayload ) -> ! {
781
781
let code = unsafe { __rust_start_panic ( msg) } ;
782
782
rtabort ! ( "failed to initiate panic, error {code}" )
783
783
}
0 commit comments