@@ -67,7 +67,7 @@ macro_rules! rtunwrap {
67
67
} ;
68
68
}
69
69
70
- fn handle_rt_panic ( e : Box < dyn Any + Send > ) {
70
+ fn handle_rt_panic < T > ( e : Box < dyn Any + Send > ) -> T {
71
71
mem:: forget ( e) ;
72
72
rtabort ! ( "initialization or cleanup bug" ) ;
73
73
}
@@ -168,19 +168,27 @@ fn lang_start_internal(
168
168
// panic is a std implementation bug. A quite likely one too, as there isn't any way to
169
169
// prevent std from accidentally introducing a panic to these functions. Another is from
170
170
// user code from `main` or, more nefariously, as described in e.g. issue #86030.
171
- // SAFETY: Only called once during runtime initialization.
172
- panic:: catch_unwind ( move || unsafe { init ( argc, argv, sigpipe) } )
173
- . unwrap_or_else ( handle_rt_panic) ;
174
- let ret_code = panic:: catch_unwind ( move || panic:: catch_unwind ( main) . unwrap_or ( 101 ) as isize )
175
- . map_err ( move |e| {
176
- mem:: forget ( e) ;
177
- rtabort ! ( "drop of the panic payload panicked" ) ;
178
- } ) ;
179
- panic:: catch_unwind ( cleanup) . unwrap_or_else ( handle_rt_panic) ;
180
- // Guard against multiple threads calling `libc::exit` concurrently.
181
- // See the documentation for `unique_thread_exit` for more information.
182
- panic:: catch_unwind ( crate :: sys:: exit_guard:: unique_thread_exit) . unwrap_or_else ( handle_rt_panic) ;
183
- ret_code
171
+ //
172
+ // We use `catch_unwind` with `handle_rt_panic` instead of `abort_unwind` to make the error in
173
+ // case of a panic a bit nicer.
174
+ panic:: catch_unwind ( move || {
175
+ // SAFETY: Only called once during runtime initialization.
176
+ unsafe { init ( argc, argv, sigpipe) } ;
177
+ let ret_code =
178
+ panic:: catch_unwind ( move || panic:: catch_unwind ( main) . unwrap_or ( 101 ) as isize ) . map_err (
179
+ move |e| {
180
+ // Print a specific error when we abort due to a panicing payload destructor.
181
+ mem:: forget ( e) ;
182
+ rtabort ! ( "drop of the panic payload panicked" ) ;
183
+ } ,
184
+ ) ;
185
+ cleanup ( ) ;
186
+ // Guard against multiple threads calling `libc::exit` concurrently.
187
+ // See the documentation for `unique_thread_exit` for more information.
188
+ crate :: sys:: exit_guard:: unique_thread_exit ( ) ;
189
+ ret_code
190
+ } )
191
+ . unwrap_or_else ( handle_rt_panic)
184
192
}
185
193
186
194
#[ cfg( not( any( test, doctest) ) ) ]
0 commit comments