2 files changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -44,23 +44,14 @@ pub struct PanicInfo<'a> {
44
44
}
45
45
46
46
impl < ' a > PanicInfo < ' a > {
47
- #[ unstable( feature = "panic_internals" , issue = "none" ) ]
48
- #[ doc( hidden) ]
49
47
#[ inline]
50
- pub fn internal_constructor (
48
+ pub ( crate ) fn new (
51
49
location : & ' a Location < ' a > ,
50
+ payload : & ' a ( dyn Any + Send ) ,
52
51
can_unwind : bool ,
53
52
force_no_backtrace : bool ,
54
53
) -> Self {
55
- struct NoPayload ;
56
- PanicInfo { payload : & NoPayload , location, can_unwind, force_no_backtrace }
57
- }
58
-
59
- #[ unstable( feature = "panic_internals" , issue = "none" ) ]
60
- #[ doc( hidden) ]
61
- #[ inline]
62
- pub fn set_payload ( & mut self , info : & ' a ( dyn Any + Send ) ) {
63
- self . payload = info;
54
+ PanicInfo { payload, location, can_unwind, force_no_backtrace }
64
55
}
65
56
66
57
/// Returns the payload associated with the panic.
Original file line number Diff line number Diff line change @@ -775,9 +775,7 @@ fn rust_panic_with_hook(
775
775
crate :: sys:: abort_internal ( ) ;
776
776
}
777
777
778
- let mut info = PanicInfo :: internal_constructor ( location, can_unwind, force_no_backtrace) ;
779
- let hook = HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) ;
780
- match * hook {
778
+ match * HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) {
781
779
// Some platforms (like wasm) know that printing to stderr won't ever actually
782
780
// print anything, and if that's the case we can skip the default
783
781
// hook. Since string formatting happens lazily when calling `payload`
@@ -786,15 +784,12 @@ fn rust_panic_with_hook(
786
784
// formatting.)
787
785
Hook :: Default if panic_output ( ) . is_none ( ) => { }
788
786
Hook :: Default => {
789
- info. set_payload ( payload. get ( ) ) ;
790
- default_hook ( & info) ;
787
+ default_hook ( & PanicInfo :: new ( location, payload. get ( ) , can_unwind, force_no_backtrace) ) ;
791
788
}
792
789
Hook :: Custom ( ref hook) => {
793
- info. set_payload ( payload. get ( ) ) ;
794
- hook ( & info) ;
790
+ hook ( & PanicInfo :: new ( location, payload. get ( ) , can_unwind, force_no_backtrace) ) ;
795
791
}
796
- } ;
797
- drop ( hook) ;
792
+ }
798
793
799
794
// Indicate that we have finished executing the panic hook. After this point
800
795
// it is fine if there is a panic while executing destructors, as long as it
0 commit comments