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
@@ -565,14 +565,14 @@ pub fn panicking() -> bool {
565
565
#[ cfg( not( test) ) ]
566
566
#[ panic_handler]
567
567
pub fn begin_panic_handler ( info : & PanicInfo < ' _ > ) -> ! {
568
- struct PanicPayload < ' a > {
568
+ struct FormatStringPayload < ' a > {
569
569
inner : & ' a fmt:: Arguments < ' a > ,
570
570
string : Option < String > ,
571
571
}
572
572
573
- impl < ' a > PanicPayload < ' a > {
574
- fn new ( inner : & ' a fmt:: Arguments < ' a > ) -> PanicPayload < ' a > {
575
- PanicPayload { inner, string : None }
573
+ impl < ' a > FormatStringPayload < ' a > {
574
+ fn new ( inner : & ' a fmt:: Arguments < ' a > ) -> Self {
575
+ Self { inner, string : None }
576
576
}
577
577
578
578
fn fill ( & mut self ) -> & mut String {
@@ -588,7 +588,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
588
588
}
589
589
}
590
590
591
- unsafe impl < ' a > BoxMeUp for PanicPayload < ' a > {
591
+ unsafe impl < ' a > PanicPayload for FormatStringPayload < ' a > {
592
592
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
593
593
// We do two allocations here, unfortunately. But (a) they're required with the current
594
594
// scheme, and (b) we don't handle panic + OOM properly anyway (see comment in
@@ -602,9 +602,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
602
602
}
603
603
}
604
604
605
- struct StrPanicPayload ( & ' static str ) ;
605
+ struct StaticStrPayload ( & ' static str ) ;
606
606
607
- unsafe impl BoxMeUp for StrPanicPayload {
607
+ unsafe impl PanicPayload for StaticStrPayload {
608
608
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
609
609
Box :: into_raw ( Box :: new ( self . 0 ) )
610
610
}
@@ -621,15 +621,15 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
621
621
// `rust_panic_with_hook` construct a new `PanicInfo`?
622
622
if let Some ( msg) = msg. as_str ( ) {
623
623
rust_panic_with_hook (
624
- & mut StrPanicPayload ( msg) ,
624
+ & mut StaticStrPayload ( msg) ,
625
625
info. message ( ) ,
626
626
loc,
627
627
info. can_unwind ( ) ,
628
628
info. force_no_backtrace ( ) ,
629
629
) ;
630
630
} else {
631
631
rust_panic_with_hook (
632
- & mut PanicPayload :: new ( msg) ,
632
+ & mut FormatStringPayload :: new ( msg) ,
633
633
info. message ( ) ,
634
634
loc,
635
635
info. can_unwind ( ) ,
@@ -659,25 +659,25 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
659
659
let loc = Location :: caller ( ) ;
660
660
return crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
661
661
rust_panic_with_hook (
662
- & mut PanicPayload :: new ( msg) ,
662
+ & mut Payload :: new ( msg) ,
663
663
None ,
664
664
loc,
665
665
/* can_unwind */ true ,
666
666
/* force_no_backtrace */ false ,
667
667
)
668
668
} ) ;
669
669
670
- struct PanicPayload < A > {
670
+ struct Payload < A > {
671
671
inner : Option < A > ,
672
672
}
673
673
674
- impl < A : Send + ' static > PanicPayload < A > {
675
- fn new ( inner : A ) -> PanicPayload < A > {
676
- PanicPayload { inner : Some ( inner) }
674
+ impl < A : Send + ' static > Payload < A > {
675
+ fn new ( inner : A ) -> Payload < A > {
676
+ Payload { inner : Some ( inner) }
677
677
}
678
678
}
679
679
680
- unsafe impl < A : Send + ' static > BoxMeUp for PanicPayload < A > {
680
+ unsafe impl < A : Send + ' static > PanicPayload for Payload < A > {
681
681
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
682
682
// Note that this should be the only allocation performed in this code path. Currently
683
683
// this means that panic!() on OOM will invoke this code path, but then again we're not
@@ -706,7 +706,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
706
706
/// panics, panic hooks, and finally dispatching to the panic runtime to either
707
707
/// abort or unwind.
708
708
fn rust_panic_with_hook (
709
- payload : & mut dyn BoxMeUp ,
709
+ payload : & mut dyn PanicPayload ,
710
710
message : Option < & fmt:: Arguments < ' _ > > ,
711
711
location : & Location < ' _ > ,
712
712
can_unwind : bool ,
@@ -782,7 +782,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
782
782
783
783
struct RewrapBox ( Box < dyn Any + Send > ) ;
784
784
785
- unsafe impl BoxMeUp for RewrapBox {
785
+ unsafe impl PanicPayload for RewrapBox {
786
786
fn take_box ( & mut self ) -> * mut ( dyn Any + Send ) {
787
787
Box :: into_raw ( mem:: replace ( & mut self . 0 , Box :: new ( ( ) ) ) )
788
788
}
@@ -799,7 +799,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
799
799
/// yer breakpoints.
800
800
#[ inline( never) ]
801
801
#[ cfg_attr( not( test) , rustc_std_internal_symbol) ]
802
- fn rust_panic ( msg : & mut dyn BoxMeUp ) -> ! {
802
+ fn rust_panic ( msg : & mut dyn PanicPayload ) -> ! {
803
803
let code = unsafe { __rust_start_panic ( msg) } ;
804
804
rtabort ! ( "failed to initiate panic, error {code}" )
805
805
}
0 commit comments