Skip to content

Commit

Permalink
Rollup merge of rust-lang#94327 - Mark-Simulacrum:avoid-macro-sp, r=p…
Browse files Browse the repository at this point in the history
…etrochenkov

Avoid emitting full macro body into JSON errors

While investigating rust-lang#94322, it was noted that currently the JSON diagnostics for macro backtraces include the full def_site span -- the whole macro body.

It seems like this shouldn't be necessary, so this PR adjusts the span to just be the "guessed head", typically the macro name. It doesn't look like we keep enough information to synthesize a nicer span here at this time.

Atop rust-lang#92123, this reduces output for the src/test/ui/suggestions/missing-lifetime-specifier.rs test from 660 KB to 156 KB locally.
  • Loading branch information
Dylan-DPC authored Feb 24, 2022
2 parents ec44d48 + 34319ff commit 3bd163f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,14 @@ impl DiagnosticSpan {
let end = je.sm.lookup_char_pos(span.hi());
let backtrace_step = backtrace.next().map(|bt| {
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
let def_site_span =
Self::from_span_full(bt.def_site, false, None, None, [].into_iter(), je);
let def_site_span = Self::from_span_full(
je.sm.guess_head_span(bt.def_site),
false,
None,
None,
[].into_iter(),
je,
);
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.kind.descr(),
Expand Down

0 comments on commit 3bd163f

Please sign in to comment.