Group "macro expansion" notes per call span
This commit is contained in:
parent
56411443f2
commit
8c9ad8d72c
6 changed files with 31 additions and 23 deletions
|
@ -388,11 +388,13 @@ impl Handler {
|
||||||
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||||
self.emit(&sp.into(), msg, Note);
|
self.emit(&sp.into(), msg, Note);
|
||||||
}
|
}
|
||||||
pub fn span_label_without_error(&self, sp: Span, msg: &str, lbl: &str) {
|
pub fn span_note_diag<'a>(&'a self,
|
||||||
|
sp: Span,
|
||||||
|
msg: &str)
|
||||||
|
-> DiagnosticBuilder<'a> {
|
||||||
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
||||||
db.set_span(sp);
|
db.set_span(sp);
|
||||||
db.span_label(sp, &lbl);
|
db
|
||||||
db.emit();
|
|
||||||
}
|
}
|
||||||
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
||||||
self.span_bug(sp, &format!("unimplemented {}", msg));
|
self.span_bug(sp, &format!("unimplemented {}", msg));
|
||||||
|
|
|
@ -24,6 +24,7 @@ use ptr::P;
|
||||||
use symbol::Symbol;
|
use symbol::Symbol;
|
||||||
use util::small_vector::SmallVector;
|
use util::small_vector::SmallVector;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
@ -643,6 +644,7 @@ pub struct ExtCtxt<'a> {
|
||||||
pub resolver: &'a mut Resolver,
|
pub resolver: &'a mut Resolver,
|
||||||
pub resolve_err_count: usize,
|
pub resolve_err_count: usize,
|
||||||
pub current_expansion: ExpansionData,
|
pub current_expansion: ExpansionData,
|
||||||
|
pub expansions: HashMap<Span, Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExtCtxt<'a> {
|
impl<'a> ExtCtxt<'a> {
|
||||||
|
@ -662,6 +664,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
||||||
directory_ownership: DirectoryOwnership::Owned,
|
directory_ownership: DirectoryOwnership::Owned,
|
||||||
},
|
},
|
||||||
|
expansions: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,8 +768,14 @@ impl<'a> ExtCtxt<'a> {
|
||||||
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
|
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
|
||||||
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||||
}
|
}
|
||||||
pub fn span_label_without_error(&self, sp: Span, msg: &str, label: &str) {
|
pub fn trace_macros_diag(&self) {
|
||||||
self.parse_sess.span_diagnostic.span_label_without_error(sp, msg, label);
|
for (sp, notes) in self.expansions.iter() {
|
||||||
|
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
|
||||||
|
for note in notes {
|
||||||
|
db.note(¬e);
|
||||||
|
}
|
||||||
|
db.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn bug(&self, msg: &str) -> ! {
|
pub fn bug(&self, msg: &str) -> ! {
|
||||||
self.parse_sess.span_diagnostic.bug(msg);
|
self.parse_sess.span_diagnostic.bug(msg);
|
||||||
|
|
|
@ -231,7 +231,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
self.cx.trace_macros_diag();
|
||||||
krate
|
krate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ use symbol::Symbol;
|
||||||
use tokenstream::{TokenStream, TokenTree};
|
use tokenstream::{TokenStream, TokenTree};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap};
|
use std::collections::HashMap;
|
||||||
use std::collections::hash_map::{Entry};
|
use std::collections::hash_map::Entry;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct ParserAnyMacro<'a> {
|
pub struct ParserAnyMacro<'a> {
|
||||||
|
@ -85,7 +85,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given `lhses` and `rhses`, this is the new macro we create
|
/// Given `lhses` and `rhses`, this is the new macro we create
|
||||||
fn generic_extension<'cx>(cx: &'cx ExtCtxt,
|
fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: ast::Ident,
|
name: ast::Ident,
|
||||||
arg: TokenStream,
|
arg: TokenStream,
|
||||||
|
@ -93,9 +93,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
|
||||||
rhses: &[quoted::TokenTree])
|
rhses: &[quoted::TokenTree])
|
||||||
-> Box<MacResult+'cx> {
|
-> Box<MacResult+'cx> {
|
||||||
if cx.trace_macros() {
|
if cx.trace_macros() {
|
||||||
cx.span_label_without_error(sp,
|
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
|
||||||
&"trace_macro",
|
let mut values: &mut Vec<String> = cx.expansions.entry(sp).or_insert(vec![]);
|
||||||
&format!("expands to `{}! {{ {} }}`", name, arg));
|
values.push(format!("expands to `{}! {{ {} }}`", name, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Which arm's failure should we report? (the one furthest along)
|
// Which arm's failure should we report? (the one furthest along)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
// compile-flags: -Z trace-macros
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, World!");
|
println!("Hello, World!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
note: trace_macro
|
note: trace_macro
|
||||||
--> $DIR/trace-macro.rs:12:5
|
--> $DIR/trace-macro.rs:14:5
|
||||||
|
|
|
|
||||||
12 | println!("Hello, World!");
|
14 | println!("Hello, World!");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `println! { "Hello, World!" }`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
note: trace_macro
|
= note: expands to `println! { "Hello, World!" }`
|
||||||
--> $DIR/trace-macro.rs:12:5
|
= note: expands to `print! { concat ! ( "Hello, World!" , "/n" ) }`
|
||||||
|
|
|
||||||
12 | println!("Hello, World!");
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `print! { concat ! ( "Hello, World!" , "\n" ) }`
|
|
||||||
|
|
|
||||||
= note: this error originates in a macro outside of the current crate
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue