Skip to content

Commit

Permalink
Don't print the macro definition site in backtraces
Browse files Browse the repository at this point in the history
This halves the backtrace length. The definition site wasn't very useful
anyways, since it may be invalid (for compiler expansions) or located in
another crate. Since the macro name is still printed, grepping for it is
still an easy way of finding the definition.
  • Loading branch information
jonas-schievink committed Sep 10, 2015
1 parent 49d8b0d commit 31fa44b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
8 changes: 2 additions & 6 deletions src/libsyntax/diagnostic.rs
Expand Up @@ -732,21 +732,17 @@ impl EmitterWriter {
sp_opt = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> io::Result<_> {
match expn_info {
Some(ei) => {
let ss = ei.callee.span.map_or(String::new(),
|span| cm.span_to_string(span));
let (pre, post) = match ei.callee.format {
codemap::MacroAttribute(..) => ("#[", "]"),
codemap::MacroBang(..) => ("", "!"),
codemap::CompilerExpansion(..) => ("", ""),
};
try!(self.print_diagnostic(&ss, Note,
&format!("in expansion of {}{}{}",
try!(self.print_diagnostic(&cm.span_to_string(ei.call_site), Note,
&format!("in this expansion of {}{}{}",
pre,
ei.callee.name(),
post),
None));
let ss = cm.span_to_string(ei.call_site);
try!(self.print_diagnostic(&ss, Note, "expansion site", None));
Ok(Some(ei.call_site))
}
None => Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/for-expn-2.rs
Expand Up @@ -10,7 +10,7 @@

// Test that we get an expansion stack for `for` loops.

// error-pattern:in expansion of for loop expansion
// error-pattern:in this expansion of for loop expansion

fn main() {
for t in &foo {
Expand Down
18 changes: 10 additions & 8 deletions src/test/compile-fail/macro-backtrace-invalid-internals.rs
Expand Up @@ -10,25 +10,25 @@

// Macros in statement vs expression position handle backtraces differently.

macro_rules! fake_method_stmt { //~ NOTE in expansion of
macro_rules! fake_method_stmt {
() => {
1.fake() //~ ERROR no method named `fake` found
}
}

macro_rules! fake_field_stmt { //~ NOTE in expansion of
macro_rules! fake_field_stmt {
() => {
1.fake //~ ERROR no field with that name
}
}

macro_rules! fake_anon_field_stmt { //~ NOTE in expansion of
macro_rules! fake_anon_field_stmt {
() => {
(1).0 //~ ERROR type was not a tuple
}
}

macro_rules! fake_method_expr { //~ NOTE in expansion of
macro_rules! fake_method_expr {
() => {
1.fake() //~ ERROR no method named `fake` found
}
Expand All @@ -47,11 +47,13 @@ macro_rules! fake_anon_field_expr {
}

fn main() {
fake_method_stmt!(); //~ NOTE expansion site
fake_field_stmt!(); //~ NOTE expansion site
fake_anon_field_stmt!(); //~ NOTE expansion site
fake_method_stmt!(); //~ NOTE in this expansion of
fake_field_stmt!(); //~ NOTE in this expansion of
fake_anon_field_stmt!(); //~ NOTE in this expansion of

let _ = fake_method_expr!(); //~ NOTE expansion site
let _ = fake_method_expr!(); //~ NOTE in this expansion of
let _ = fake_field_expr!(); //~ ERROR no field with that name
//~^ NOTE in this expansion of
let _ = fake_anon_field_expr!(); //~ ERROR type was not a tuple
//~^ NOTE in this expansion of
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/macro-backtrace-nested.rs
Expand Up @@ -19,11 +19,11 @@ macro_rules! call_nested_expr {
() => (nested_expr!())
}

macro_rules! call_nested_expr_sum { //~ NOTE in expansion of
macro_rules! call_nested_expr_sum {
() => { 1 + nested_expr!(); } //~ ERROR unresolved name
}

fn main() {
1 + call_nested_expr!(); //~ ERROR unresolved name
call_nested_expr_sum!(); //~ NOTE expansion site
call_nested_expr_sum!(); //~ NOTE in this expansion of
}
9 changes: 5 additions & 4 deletions src/test/compile-fail/macro-backtrace-println.rs
Expand Up @@ -16,14 +16,15 @@

fn print(_args: std::fmt::Arguments) {}

macro_rules! myprint { //~ NOTE in expansion of
($($arg:tt)*) => (print(format_args!($($arg)*)));
macro_rules! myprint {
($($arg:tt)*) => (print(format_args!($($arg)*))); //~ NOTE in this expansion of
}

macro_rules! myprintln { //~ NOTE in expansion of
macro_rules! myprintln {
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ ERROR invalid reference to argument `0`
//~^ NOTE in this expansion of
}

fn main() {
myprintln!("{}"); //~ NOTE expansion site
myprintln!("{}"); //~ NOTE in this expansion of
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/method-macro-backtrace.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// forbid-output: in expansion of
// forbid-output: in this expansion of

macro_rules! make_method {
($name:ident) => ( fn $name(&self) { } )
Expand Down

0 comments on commit 31fa44b

Please sign in to comment.