From 036e538e06589d84f058e7d90d6172b519e6616a Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 11 Apr 2024 17:27:49 -0400 Subject: [PATCH] Call the panic hook for non-unwind panics in proc-macros --- library/proc_macro/src/bridge/client.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs index f3cfc41bac7c6..faca745e56f74 100644 --- a/library/proc_macro/src/bridge/client.rs +++ b/library/proc_macro/src/bridge/client.rs @@ -283,7 +283,11 @@ fn maybe_install_panic_hook(force_show_panics: bool) { HIDE_PANICS_DURING_EXPANSION.call_once(|| { let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { - if force_show_panics || !is_available() { + // We normally report panics by catching unwinds and passing the payload from the + // unwind back to the compiler, but if the panic doesn't unwind we'll abort before + // the compiler has a chance to print an error. So we special-case PanicInfo where + // can_unwind is false. + if force_show_panics || !is_available() || !info.can_unwind() { prev(info) } }));