mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-21 12:07:31 +00:00
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.
This commit is contained in:
commit
c59199efca
@ -305,6 +305,7 @@ impl Bridge<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn enter<R>(self, f: impl FnOnce() -> R) -> R {
|
fn enter<R>(self, f: impl FnOnce() -> R) -> R {
|
||||||
|
let force_show_panics = self.force_show_panics;
|
||||||
// Hide the default panic output within `proc_macro` expansions.
|
// Hide the default panic output within `proc_macro` expansions.
|
||||||
// NB. the server can't do this because it may use a different libstd.
|
// NB. the server can't do this because it may use a different libstd.
|
||||||
static HIDE_PANICS_DURING_EXPANSION: Once = Once::new();
|
static HIDE_PANICS_DURING_EXPANSION: Once = Once::new();
|
||||||
@ -313,9 +314,7 @@ impl Bridge<'_> {
|
|||||||
panic::set_hook(Box::new(move |info| {
|
panic::set_hook(Box::new(move |info| {
|
||||||
let show = BridgeState::with(|state| match state {
|
let show = BridgeState::with(|state| match state {
|
||||||
BridgeState::NotConnected => true,
|
BridgeState::NotConnected => true,
|
||||||
// Something weird is going on, so don't suppress any backtraces
|
BridgeState::Connected(_) | BridgeState::InUse => force_show_panics,
|
||||||
BridgeState::InUse => true,
|
|
||||||
BridgeState::Connected(bridge) => bridge.force_show_panics,
|
|
||||||
});
|
});
|
||||||
if show {
|
if show {
|
||||||
prev(info)
|
prev(info)
|
||||||
|
13
src/test/ui-fulldeps/auxiliary/proc-macro-panic.rs
Normal file
13
src/test/ui-fulldeps/auxiliary/proc-macro-panic.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// force-host
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type = "proc-macro"]
|
||||||
|
|
||||||
|
extern crate proc_macro;
|
||||||
|
use proc_macro::{TokenStream, Ident, Span};
|
||||||
|
|
||||||
|
#[proc_macro]
|
||||||
|
pub fn panic_in_libproc_macro(_: TokenStream) -> TokenStream {
|
||||||
|
Ident::new("", Span::call_site());
|
||||||
|
TokenStream::new()
|
||||||
|
}
|
17
src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.rs
Normal file
17
src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// aux-build:proc-macro-panic.rs
|
||||||
|
// edition:2018
|
||||||
|
// ignore-stage1
|
||||||
|
// only-linux
|
||||||
|
//
|
||||||
|
// FIXME: This should be a normal (stage1, all platforms) test in
|
||||||
|
// src/test/ui/proc-macro once issue #59998 is fixed.
|
||||||
|
|
||||||
|
// Regression test for issue #76270
|
||||||
|
// Tests that we don't print an ICE message when a panic
|
||||||
|
// occurs in libproc-macro (when `-Z proc-macro-backtrace` is not specified)
|
||||||
|
|
||||||
|
extern crate proc_macro_panic;
|
||||||
|
|
||||||
|
proc_macro_panic::panic_in_libproc_macro!(); //~ ERROR proc macro panicked
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,10 @@
|
|||||||
|
error: proc macro panicked
|
||||||
|
--> $DIR/issue-76270-panic-in-libproc-macro.rs:15:1
|
||||||
|
|
|
||||||
|
LL | proc_macro_panic::panic_in_libproc_macro!();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: message: `""` is not a valid identifier
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user