Skip to content

Commit

Permalink
rustc_span: replace MacroBacktrace with ExpnData.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 26, 2020
1 parent a7b0aa0 commit 75284f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/librustc_errors/emitter.rs
Expand Up @@ -21,6 +21,7 @@ use crate::{

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_span::hygiene::{ExpnKind, MacroKind};
use std::borrow::Cow;
use std::cmp::{max, min, Reverse};
use std::io;
Expand Down Expand Up @@ -346,15 +347,15 @@ pub trait Emitter {
for (i, trace) in sp.macro_backtrace().iter().rev().enumerate() {
// Only show macro locations that are local
// and display them like a span_note
if trace.def_site_span.is_dummy() {
if trace.def_site.is_dummy() {
continue;
}
if always_backtrace {
new_labels.push((
trace.def_site_span,
trace.def_site,
format!(
"in this expansion of `{}`{}",
trace.macro_decl_name,
trace.kind.descr(),
if backtrace_len > 2 {
// if backtrace_len == 1 it'll be pointed
// at by "in this macro invocation"
Expand All @@ -366,9 +367,8 @@ pub trait Emitter {
));
}
// Check to make sure we're not in any <*macros>
if !sm.span_to_filename(trace.def_site_span).is_macros()
&& !trace.macro_decl_name.starts_with("desugaring of ")
&& !trace.macro_decl_name.starts_with("#[")
if !sm.span_to_filename(trace.def_site).is_macros()
&& matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _))
|| always_backtrace
{
new_labels.push((
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_errors/json.rs
Expand Up @@ -17,7 +17,8 @@ use crate::{Applicability, DiagnosticId};
use crate::{CodeSuggestion, SubDiagnostic};

use rustc_data_structures::sync::Lrc;
use rustc_span::{MacroBacktrace, MultiSpan, Span, SpanLabel};
use rustc_span::hygiene::ExpnData;
use rustc_span::{MultiSpan, Span, SpanLabel};
use std::io::{self, Write};
use std::path::Path;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -317,18 +318,18 @@ impl DiagnosticSpan {
is_primary: bool,
label: Option<String>,
suggestion: Option<(&String, Applicability)>,
mut backtrace: vec::IntoIter<MacroBacktrace>,
mut backtrace: vec::IntoIter<ExpnData>,
je: &JsonEmitter,
) -> DiagnosticSpan {
let start = je.sm.lookup_char_pos(span.lo());
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_span, false, None, None, vec![].into_iter(), je);
Self::from_span_full(bt.def_site, false, None, None, vec![].into_iter(), je);
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.macro_decl_name,
macro_decl_name: bt.kind.descr(),
def_site_span,
})
});
Expand Down
20 changes: 2 additions & 18 deletions src/librustc_span/lib.rs
Expand Up @@ -445,7 +445,7 @@ impl Span {
self.ctxt().outer_expn_data().allow_internal_unsafe
}

pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
pub fn macro_backtrace(mut self) -> Vec<ExpnData> {
let mut prev_span = DUMMY_SP;
let mut result = vec![];
loop {
Expand All @@ -455,11 +455,7 @@ impl Span {
}
// Don't print recursive invocations.
if !expn_data.call_site.source_equal(&prev_span) {
result.push(MacroBacktrace {
call_site: expn_data.call_site,
macro_decl_name: expn_data.kind.descr(),
def_site_span: expn_data.def_site,
});
result.push(expn_data.clone());
}

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

#[derive(Debug)]
pub struct MacroBacktrace {
/// span where macro was applied to generate this code
pub call_site: Span,

/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]")
pub macro_decl_name: String,

/// span where macro was defined (possibly dummy)
pub def_site_span: Span,
}

// _____________________________________________________________________________
// SpanLinesError, SpanSnippetError, DistinctSources, MalformedSourceMapPositions
//
Expand Down

0 comments on commit 75284f8

Please sign in to comment.