Rollup merge of #123825 - saethlin:report-nounwind-panics, r=petrochenkov

Call the panic hook for non-unwind panics in proc-macros

As I suggested in https://github.com/rust-lang/rust/issues/123286#issuecomment-2030344815.

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.
This commit is contained in:
Matthias Krüger 2024-04-12 17:41:34 +02:00 committed by GitHub
commit 8c8692014b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -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)
}
}));

View File

@ -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)]