Skip to content

Commit 31fa44b

Browse files
Don't print the macro definition site in backtraces
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.
1 parent 49d8b0d commit 31fa44b

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,21 +732,17 @@ impl EmitterWriter {
732732
sp_opt = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> io::Result<_> {
733733
match expn_info {
734734
Some(ei) => {
735-
let ss = ei.callee.span.map_or(String::new(),
736-
|span| cm.span_to_string(span));
737735
let (pre, post) = match ei.callee.format {
738736
codemap::MacroAttribute(..) => ("#[", "]"),
739737
codemap::MacroBang(..) => ("", "!"),
740738
codemap::CompilerExpansion(..) => ("", ""),
741739
};
742-
try!(self.print_diagnostic(&ss, Note,
743-
&format!("in expansion of {}{}{}",
740+
try!(self.print_diagnostic(&cm.span_to_string(ei.call_site), Note,
741+
&format!("in this expansion of {}{}{}",
744742
pre,
745743
ei.callee.name(),
746744
post),
747745
None));
748-
let ss = cm.span_to_string(ei.call_site);
749-
try!(self.print_diagnostic(&ss, Note, "expansion site", None));
750746
Ok(Some(ei.call_site))
751747
}
752748
None => Ok(None)

src/test/compile-fail/for-expn-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
// error-pattern:in expansion of for loop expansion
13+
// error-pattern:in this expansion of for loop expansion
1414

1515
fn main() {
1616
for t in &foo {

src/test/compile-fail/macro-backtrace-invalid-internals.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010

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

13-
macro_rules! fake_method_stmt { //~ NOTE in expansion of
13+
macro_rules! fake_method_stmt {
1414
() => {
1515
1.fake() //~ ERROR no method named `fake` found
1616
}
1717
}
1818

19-
macro_rules! fake_field_stmt { //~ NOTE in expansion of
19+
macro_rules! fake_field_stmt {
2020
() => {
2121
1.fake //~ ERROR no field with that name
2222
}
2323
}
2424

25-
macro_rules! fake_anon_field_stmt { //~ NOTE in expansion of
25+
macro_rules! fake_anon_field_stmt {
2626
() => {
2727
(1).0 //~ ERROR type was not a tuple
2828
}
2929
}
3030

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

4949
fn main() {
50-
fake_method_stmt!(); //~ NOTE expansion site
51-
fake_field_stmt!(); //~ NOTE expansion site
52-
fake_anon_field_stmt!(); //~ NOTE expansion site
50+
fake_method_stmt!(); //~ NOTE in this expansion of
51+
fake_field_stmt!(); //~ NOTE in this expansion of
52+
fake_anon_field_stmt!(); //~ NOTE in this expansion of
5353

54-
let _ = fake_method_expr!(); //~ NOTE expansion site
54+
let _ = fake_method_expr!(); //~ NOTE in this expansion of
5555
let _ = fake_field_expr!(); //~ ERROR no field with that name
56+
//~^ NOTE in this expansion of
5657
let _ = fake_anon_field_expr!(); //~ ERROR type was not a tuple
58+
//~^ NOTE in this expansion of
5759
}

src/test/compile-fail/macro-backtrace-nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ macro_rules! call_nested_expr {
1919
() => (nested_expr!())
2020
}
2121

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

2626
fn main() {
2727
1 + call_nested_expr!(); //~ ERROR unresolved name
28-
call_nested_expr_sum!(); //~ NOTE expansion site
28+
call_nested_expr_sum!(); //~ NOTE in this expansion of
2929
}

src/test/compile-fail/macro-backtrace-println.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

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

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

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

2728
fn main() {
28-
myprintln!("{}"); //~ NOTE expansion site
29+
myprintln!("{}"); //~ NOTE in this expansion of
2930
}

src/test/compile-fail/method-macro-backtrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// forbid-output: in expansion of
11+
// forbid-output: in this expansion of
1212

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

0 commit comments

Comments
 (0)