Skip to content

Commit 10b568e

Browse files
authored
Unrolled build for rust-lang#123825
Rollup merge of rust-lang#123825 - saethlin:report-nounwind-panics, r=petrochenkov Call the panic hook for non-unwind panics in proc-macros As I suggested in rust-lang#123286 (comment). If a proc macro causes a non-unwinding panic, `proc_macro` isn't able to catch the unwind and report the panic as a compile error by passing control back to the compiler. Our only chance to produce any diagnostic is the panic hook, so we should call it. This scenario has already existed, but has become a lot more interesting now that we're adding more UB-detecting panics to the standard library, and such panics do not unwind.
2 parents bd71213 + d8dc28b commit 10b568e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: library/proc_macro/src/bridge/client.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ fn maybe_install_panic_hook(force_show_panics: bool) {
283283
HIDE_PANICS_DURING_EXPANSION.call_once(|| {
284284
let prev = panic::take_hook();
285285
panic::set_hook(Box::new(move |info| {
286-
if force_show_panics || !is_available() {
286+
// We normally report panics by catching unwinds and passing the payload from the
287+
// unwind back to the compiler, but if the panic doesn't unwind we'll abort before
288+
// the compiler has a chance to print an error. So we special-case PanicInfo where
289+
// can_unwind is false.
290+
if force_show_panics || !is_available() || !info.can_unwind() {
287291
prev(info)
288292
}
289293
}));

Diff for: library/proc_macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(maybe_uninit_write_slice)]
3131
#![feature(negative_impls)]
3232
#![feature(new_uninit)]
33+
#![feature(panic_can_unwind)]
3334
#![feature(restricted_std)]
3435
#![feature(rustc_attrs)]
3536
#![feature(min_specialization)]

0 commit comments

Comments
 (0)