Skip to content

Commit c59199e

Browse files
committed
Auto merge of #76292 - Aaron1011:fix/proc-macro-panic-hide, r=petrochenkov
Respect `-Z proc-macro-backtrace` flag for panics inside libproc_macro Fixes #76270 Previously, any panic occuring during a call to a libproc_macro method (e.g. calling `Ident::new` with an invalid identifier) would always cause an ICE message to be printed.
2 parents 42d896a + 53cce25 commit c59199e

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

library/proc_macro/src/bridge/client.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ impl Bridge<'_> {
305305
}
306306

307307
fn enter<R>(self, f: impl FnOnce() -> R) -> R {
308+
let force_show_panics = self.force_show_panics;
308309
// Hide the default panic output within `proc_macro` expansions.
309310
// NB. the server can't do this because it may use a different libstd.
310311
static HIDE_PANICS_DURING_EXPANSION: Once = Once::new();
@@ -313,9 +314,7 @@ impl Bridge<'_> {
313314
panic::set_hook(Box::new(move |info| {
314315
let show = BridgeState::with(|state| match state {
315316
BridgeState::NotConnected => true,
316-
// Something weird is going on, so don't suppress any backtraces
317-
BridgeState::InUse => true,
318-
BridgeState::Connected(bridge) => bridge.force_show_panics,
317+
BridgeState::Connected(_) | BridgeState::InUse => force_show_panics,
319318
});
320319
if show {
321320
prev(info)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::{TokenStream, Ident, Span};
8+
9+
#[proc_macro]
10+
pub fn panic_in_libproc_macro(_: TokenStream) -> TokenStream {
11+
Ident::new("", Span::call_site());
12+
TokenStream::new()
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:proc-macro-panic.rs
2+
// edition:2018
3+
// ignore-stage1
4+
// only-linux
5+
//
6+
// FIXME: This should be a normal (stage1, all platforms) test in
7+
// src/test/ui/proc-macro once issue #59998 is fixed.
8+
9+
// Regression test for issue #76270
10+
// Tests that we don't print an ICE message when a panic
11+
// occurs in libproc-macro (when `-Z proc-macro-backtrace` is not specified)
12+
13+
extern crate proc_macro_panic;
14+
15+
proc_macro_panic::panic_in_libproc_macro!(); //~ ERROR proc macro panicked
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: proc macro panicked
2+
--> $DIR/issue-76270-panic-in-libproc-macro.rs:15:1
3+
|
4+
LL | proc_macro_panic::panic_in_libproc_macro!();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: message: `""` is not a valid identifier
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)