about summary refs log tree commit diff
path: root/library/proc_macro
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2024-04-11 17:27:49 -0400
committerBen Kimock <kimockb@gmail.com>2024-04-11 17:46:12 -0400
commitd8dc28b93e4cbfe2a3c26af06c73b0ea46f67a1e (patch)
treea6c59319cf146fd2a08589ba5fa7fd6036d19775 /library/proc_macro
parentaa6a697a1c75b0aa06954136f7641706edadc2be (diff)
downloadrust-d8dc28b93e4cbfe2a3c26af06c73b0ea46f67a1e.tar.gz
rust-d8dc28b93e4cbfe2a3c26af06c73b0ea46f67a1e.zip
Call the panic hook for non-unwind panics in proc-macros
Diffstat (limited to 'library/proc_macro')
-rw-r--r--library/proc_macro/src/bridge/client.rs6
-rw-r--r--library/proc_macro/src/lib.rs1
2 files changed, 6 insertions, 1 deletions
diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs
index f3cfc41bac7..faca745e56f 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 01c449563ee..a3ebef45c88 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)]