Auto merge of #75082 - Aaron1011:feature/proc-macro-backtrace, r=petrochenkov
Add `-Z proc-macro-backtrace` to allow showing proc-macro panics Fixes #75050 Previously, we would unconditionally suppress the panic hook during proc-macro execution. This commit adds a new flag `-Z proc-macro-backtrace`, which allows running the panic hook for easier debugging.
This commit is contained in:
commit
e98f0632bb
10 changed files with 99 additions and 27 deletions
|
@ -1788,6 +1788,7 @@ pub struct ExpansionConfig<'feat> {
|
|||
pub should_test: bool, // If false, strip `#[test]` nodes
|
||||
pub keep_macs: bool,
|
||||
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
|
||||
pub proc_macro_backtrace: bool, // If true, show backtraces for proc-macro panics
|
||||
}
|
||||
|
||||
impl<'feat> ExpansionConfig<'feat> {
|
||||
|
@ -1800,6 +1801,7 @@ impl<'feat> ExpansionConfig<'feat> {
|
|||
should_test: false,
|
||||
keep_macs: false,
|
||||
span_debug: false,
|
||||
proc_macro_backtrace: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ impl base::ProcMacro for BangProcMacro {
|
|||
input: TokenStream,
|
||||
) -> Result<TokenStream, ErrorReported> {
|
||||
let server = proc_macro_server::Rustc::new(ecx);
|
||||
self.client.run(&EXEC_STRATEGY, server, input).map_err(|e| {
|
||||
self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace).map_err(|e| {
|
||||
let mut err = ecx.struct_span_err(span, "proc macro panicked");
|
||||
if let Some(s) = e.as_str() {
|
||||
err.help(&format!("message: {}", s));
|
||||
|
@ -48,14 +48,16 @@ impl base::AttrProcMacro for AttrProcMacro {
|
|||
annotated: TokenStream,
|
||||
) -> Result<TokenStream, ErrorReported> {
|
||||
let server = proc_macro_server::Rustc::new(ecx);
|
||||
self.client.run(&EXEC_STRATEGY, server, annotation, annotated).map_err(|e| {
|
||||
let mut err = ecx.struct_span_err(span, "custom attribute panicked");
|
||||
if let Some(s) = e.as_str() {
|
||||
err.help(&format!("message: {}", s));
|
||||
}
|
||||
err.emit();
|
||||
ErrorReported
|
||||
})
|
||||
self.client
|
||||
.run(&EXEC_STRATEGY, server, annotation, annotated, ecx.ecfg.proc_macro_backtrace)
|
||||
.map_err(|e| {
|
||||
let mut err = ecx.struct_span_err(span, "custom attribute panicked");
|
||||
if let Some(s) = e.as_str() {
|
||||
err.help(&format!("message: {}", s));
|
||||
}
|
||||
err.emit();
|
||||
ErrorReported
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,17 +113,18 @@ impl MultiItemModifier for ProcMacroDerive {
|
|||
};
|
||||
|
||||
let server = proc_macro_server::Rustc::new(ecx);
|
||||
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
|
||||
Ok(stream) => stream,
|
||||
Err(e) => {
|
||||
let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
|
||||
if let Some(s) = e.as_str() {
|
||||
err.help(&format!("message: {}", s));
|
||||
let stream =
|
||||
match self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace) {
|
||||
Ok(stream) => stream,
|
||||
Err(e) => {
|
||||
let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
|
||||
if let Some(s) = e.as_str() {
|
||||
err.help(&format!("message: {}", s));
|
||||
}
|
||||
err.emit();
|
||||
return ExpandResult::Ready(vec![]);
|
||||
}
|
||||
err.emit();
|
||||
return ExpandResult::Ready(vec![]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let error_count_before = ecx.sess.parse_sess.span_diagnostic.err_count();
|
||||
let mut parser =
|
||||
|
|
|
@ -291,6 +291,7 @@ fn configure_and_expand_inner<'a>(
|
|||
trace_mac: sess.opts.debugging_opts.trace_macros,
|
||||
should_test: sess.opts.test,
|
||||
span_debug: sess.opts.debugging_opts.span_debug,
|
||||
proc_macro_backtrace: sess.opts.debugging_opts.proc_macro_backtrace,
|
||||
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
|
||||
};
|
||||
|
||||
|
|
|
@ -502,6 +502,7 @@ fn test_debugging_options_tracking_hash() {
|
|||
untracked!(print_llvm_passes, true);
|
||||
untracked!(print_mono_items, Some(String::from("abc")));
|
||||
untracked!(print_type_sizes, true);
|
||||
untracked!(proc_macro_backtrace, true);
|
||||
untracked!(query_dep_graph, true);
|
||||
untracked!(query_stats, true);
|
||||
untracked!(save_analysis, true);
|
||||
|
|
|
@ -967,6 +967,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||
"print the result of the monomorphization collection pass"),
|
||||
print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
|
||||
"print layout information for each type encountered (default: no)"),
|
||||
proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
|
||||
"show backtraces for panics during proc-macro execution (default: no)"),
|
||||
profile: bool = (false, parse_bool, [TRACKED],
|
||||
"insert profiling code (default: no)"),
|
||||
profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue