@@ -29,7 +29,7 @@ use intrinsics;
2929use mem;
3030use ptr;
3131use raw;
32- use sys:: stdio:: { Stderr , stderr_prints_nothing } ;
32+ use sys:: stdio:: panic_output ;
3333use sys_common:: rwlock:: RWLock ;
3434use sys_common:: thread_info;
3535use sys_common:: util;
@@ -193,7 +193,6 @@ fn default_hook(info: &PanicInfo) {
193193 None => "Box<Any>" ,
194194 }
195195 } ;
196- let mut err = Stderr :: new ( ) . ok ( ) ;
197196 let thread = thread_info:: current_thread ( ) ;
198197 let name = thread. as_ref ( ) . and_then ( |t| t. name ( ) ) . unwrap_or ( "<unnamed>" ) ;
199198
@@ -215,17 +214,14 @@ fn default_hook(info: &PanicInfo) {
215214 }
216215 } ;
217216
218- let prev = LOCAL_STDERR . with ( |s| s. borrow_mut ( ) . take ( ) ) ;
219- match ( prev, err. as_mut ( ) ) {
220- ( Some ( mut stderr) , _) => {
221- write ( & mut * stderr) ;
222- let mut s = Some ( stderr) ;
223- LOCAL_STDERR . with ( |slot| {
224- * slot. borrow_mut ( ) = s. take ( ) ;
225- } ) ;
226- }
227- ( None , Some ( ref mut err) ) => { write ( err) }
228- _ => { }
217+ if let Some ( mut local) = LOCAL_STDERR . with ( |s| s. borrow_mut ( ) . take ( ) ) {
218+ write ( & mut * local) ;
219+ let mut s = Some ( local) ;
220+ LOCAL_STDERR . with ( |slot| {
221+ * slot. borrow_mut ( ) = s. take ( ) ;
222+ } ) ;
223+ } else if let Some ( mut out) = panic_output ( ) {
224+ write ( & mut out) ;
229225 }
230226}
231227
@@ -485,7 +481,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp,
485481 // Some platforms know that printing to stderr won't ever actually
486482 // print anything, and if that's the case we can skip the default
487483 // hook.
488- Hook :: Default if stderr_prints_nothing ( ) => { }
484+ Hook :: Default if panic_output ( ) . is_none ( ) => { }
489485 Hook :: Default => {
490486 info. set_payload ( payload. get ( ) ) ;
491487 default_hook ( & info) ;
@@ -494,7 +490,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp,
494490 info. set_payload ( payload. get ( ) ) ;
495491 ( * ptr) ( & info) ;
496492 }
497- }
493+ } ;
498494 HOOK_LOCK . read_unlock ( ) ;
499495 }
500496
0 commit comments