From d8dc28b93e4cbfe2a3c26af06c73b0ea46f67a1e 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 +++++- library/proc_macro/src/lib.rs | 1 + 2 files changed, 6 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) } })); diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 01c449563ee92..a3ebef45c8849 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -30,6 +30,7 @@ #![feature(maybe_uninit_write_slice)] #![feature(negative_impls)] #![feature(new_uninit)] +#![feature(panic_can_unwind)] #![feature(restricted_std)] #![feature(rustc_attrs)] #![feature(min_specialization)]