diff options
| author | bors <bors@rust-lang.org> | 2020-01-26 21:01:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-01-26 21:01:13 +0000 |
| commit | a237641c7df8125b89b8f9c2a3594964ba8188f8 (patch) | |
| tree | 105db4bbe1eb9f95251c1414f926a3e3f36602cb /src/librustc_errors | |
| parent | 698fcd38fa9548e64a2092ff48c9d15ceb57d40c (diff) | |
| parent | 6980f82c0d152446506fee4d4a45d8afdf4ad9a4 (diff) | |
Auto merge of #68407 - eddyb:iter-macro-backtrace, r=petrochenkov
rustc_span: return an impl Iterator instead of a Vec from macro_backtrace. Having `Span::macro_backtrace` produce an `impl Iterator<Item = ExpnData>` allows #67359 to use it instead of rolling its own similar functionality. The move from `MacroBacktrace` to `ExpnData` (which the first two commits are prerequisites for) both eliminates unnecessary allocations, and is strictly more flexible (exposes more information). r? @petrochenkov
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 20 | ||||
| -rw-r--r-- | src/librustc_errors/json.rs | 11 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 7218730538a..f9e23e96fa8 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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; @@ -342,19 +343,20 @@ pub trait Emitter { if call_sp != *sp && !always_backtrace { before_after.push((*sp, call_sp)); } - let backtrace_len = sp.macro_backtrace().len(); - for (i, trace) in sp.macro_backtrace().iter().rev().enumerate() { + let macro_backtrace: Vec<_> = sp.macro_backtrace().collect(); + let backtrace_len = macro_backtrace.len(); + for (i, trace) in 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" @@ -366,9 +368,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(( @@ -398,8 +399,7 @@ pub trait Emitter { continue; } if sm.span_to_filename(sp_label.span.clone()).is_macros() && !always_backtrace { - let v = sp_label.span.macro_backtrace(); - if let Some(use_site) = v.last() { + if let Some(use_site) = sp_label.span.macro_backtrace().last() { before_after.push((sp_label.span.clone(), use_site.call_site.clone())); } } diff --git a/src/librustc_errors/json.rs b/src/librustc_errors/json.rs index 29d3122636e..3ddf9b09893 100644 --- a/src/librustc_errors/json.rs +++ b/src/librustc_errors/json.rs @@ -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}; @@ -308,7 +309,7 @@ impl DiagnosticSpan { // backtrace ourselves, but the `macro_backtrace` helper makes // some decision, such as dropping some frames, and I don't // want to duplicate that logic here. - let backtrace = span.macro_backtrace().into_iter(); + let backtrace = span.macro_backtrace(); DiagnosticSpan::from_span_full(span, is_primary, label, suggestion, backtrace, je) } @@ -317,7 +318,7 @@ impl DiagnosticSpan { is_primary: bool, label: Option<String>, suggestion: Option<(&String, Applicability)>, - mut backtrace: vec::IntoIter<MacroBacktrace>, + mut backtrace: impl Iterator<Item = ExpnData>, je: &JsonEmitter, ) -> DiagnosticSpan { let start = je.sm.lookup_char_pos(span.lo()); @@ -325,10 +326,10 @@ impl DiagnosticSpan { 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, }) }); |
