Skip to content

Commit 75284f8

Browse files
committed
rustc_span: replace MacroBacktrace with ExpnData.
1 parent a7b0aa0 commit 75284f8

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

src/librustc_errors/emitter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121

2222
use rustc_data_structures::fx::FxHashMap;
2323
use rustc_data_structures::sync::Lrc;
24+
use rustc_span::hygiene::{ExpnKind, MacroKind};
2425
use std::borrow::Cow;
2526
use std::cmp::{max, min, Reverse};
2627
use std::io;
@@ -346,15 +347,15 @@ pub trait Emitter {
346347
for (i, trace) in sp.macro_backtrace().iter().rev().enumerate() {
347348
// Only show macro locations that are local
348349
// and display them like a span_note
349-
if trace.def_site_span.is_dummy() {
350+
if trace.def_site.is_dummy() {
350351
continue;
351352
}
352353
if always_backtrace {
353354
new_labels.push((
354-
trace.def_site_span,
355+
trace.def_site,
355356
format!(
356357
"in this expansion of `{}`{}",
357-
trace.macro_decl_name,
358+
trace.kind.descr(),
358359
if backtrace_len > 2 {
359360
// if backtrace_len == 1 it'll be pointed
360361
// at by "in this macro invocation"
@@ -366,9 +367,8 @@ pub trait Emitter {
366367
));
367368
}
368369
// Check to make sure we're not in any <*macros>
369-
if !sm.span_to_filename(trace.def_site_span).is_macros()
370-
&& !trace.macro_decl_name.starts_with("desugaring of ")
371-
&& !trace.macro_decl_name.starts_with("#[")
370+
if !sm.span_to_filename(trace.def_site).is_macros()
371+
&& matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _))
372372
|| always_backtrace
373373
{
374374
new_labels.push((

src/librustc_errors/json.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::{Applicability, DiagnosticId};
1717
use crate::{CodeSuggestion, SubDiagnostic};
1818

1919
use rustc_data_structures::sync::Lrc;
20-
use rustc_span::{MacroBacktrace, MultiSpan, Span, SpanLabel};
20+
use rustc_span::hygiene::ExpnData;
21+
use rustc_span::{MultiSpan, Span, SpanLabel};
2122
use std::io::{self, Write};
2223
use std::path::Path;
2324
use std::sync::{Arc, Mutex};
@@ -317,18 +318,18 @@ impl DiagnosticSpan {
317318
is_primary: bool,
318319
label: Option<String>,
319320
suggestion: Option<(&String, Applicability)>,
320-
mut backtrace: vec::IntoIter<MacroBacktrace>,
321+
mut backtrace: vec::IntoIter<ExpnData>,
321322
je: &JsonEmitter,
322323
) -> DiagnosticSpan {
323324
let start = je.sm.lookup_char_pos(span.lo());
324325
let end = je.sm.lookup_char_pos(span.hi());
325326
let backtrace_step = backtrace.next().map(|bt| {
326327
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
327328
let def_site_span =
328-
Self::from_span_full(bt.def_site_span, false, None, None, vec![].into_iter(), je);
329+
Self::from_span_full(bt.def_site, false, None, None, vec![].into_iter(), je);
329330
Box::new(DiagnosticSpanMacroExpansion {
330331
span: call_site,
331-
macro_decl_name: bt.macro_decl_name,
332+
macro_decl_name: bt.kind.descr(),
332333
def_site_span,
333334
})
334335
});

src/librustc_span/lib.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl Span {
445445
self.ctxt().outer_expn_data().allow_internal_unsafe
446446
}
447447

448-
pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
448+
pub fn macro_backtrace(mut self) -> Vec<ExpnData> {
449449
let mut prev_span = DUMMY_SP;
450450
let mut result = vec![];
451451
loop {
@@ -455,11 +455,7 @@ impl Span {
455455
}
456456
// Don't print recursive invocations.
457457
if !expn_data.call_site.source_equal(&prev_span) {
458-
result.push(MacroBacktrace {
459-
call_site: expn_data.call_site,
460-
macro_decl_name: expn_data.kind.descr(),
461-
def_site_span: expn_data.def_site,
462-
});
458+
result.push(expn_data.clone());
463459
}
464460

465461
prev_span = self;
@@ -1501,18 +1497,6 @@ pub struct FileLines {
15011497
pub static SPAN_DEBUG: AtomicRef<fn(Span, &mut fmt::Formatter<'_>) -> fmt::Result> =
15021498
AtomicRef::new(&(default_span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
15031499

1504-
#[derive(Debug)]
1505-
pub struct MacroBacktrace {
1506-
/// span where macro was applied to generate this code
1507-
pub call_site: Span,
1508-
1509-
/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]")
1510-
pub macro_decl_name: String,
1511-
1512-
/// span where macro was defined (possibly dummy)
1513-
pub def_site_span: Span,
1514-
}
1515-
15161500
// _____________________________________________________________________________
15171501
// SpanLinesError, SpanSnippetError, DistinctSources, MalformedSourceMapPositions
15181502
//

0 commit comments

Comments
 (0)