diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 02d8297dd461..06aafa050529 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -388,6 +388,12 @@ impl Handler { pub fn span_note_without_error>(&self, sp: S, msg: &str) { self.emit(&sp.into(), msg, Note); } + pub fn span_label_without_error(&self, sp: Span, msg: &str, lbl: &str) { + let mut db = DiagnosticBuilder::new(self, Note, msg); + db.set_span(sp); + db.span_label(sp, &lbl); + db.emit(); + } pub fn span_unimpl>(&self, sp: S, msg: &str) -> ! { self.span_bug(sp, &format!("unimplemented {}", msg)); } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index fda026fec64e..3bfa63a022d0 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -765,6 +765,9 @@ impl<'a> ExtCtxt<'a> { pub fn span_bug(&self, sp: Span, msg: &str) -> ! { self.parse_sess.span_diagnostic.span_bug(sp, msg); } + pub fn span_label_without_error(&self, sp: Span, msg: &str, label: &str) { + self.parse_sess.span_diagnostic.span_label_without_error(sp, msg, label); + } pub fn bug(&self, msg: &str) -> ! { self.parse_sess.span_diagnostic.bug(msg); } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index be979960725a..46c49ffb24c4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -93,7 +93,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, rhses: &[quoted::TokenTree]) -> Box { if cx.trace_macros() { - println!("{}! {{ {} }}", name, arg); + cx.span_label_without_error(sp, + &"trace_macro", + &format!("expands to `{}! {{ {} }}`", name, arg)); } // Which arm's failure should we report? (the one furthest along) diff --git a/src/test/run-make/trace-macros-flag/Makefile b/src/test/run-make/trace-macros-flag/Makefile deleted file mode 100644 index 3338e394e0ef..000000000000 --- a/src/test/run-make/trace-macros-flag/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# This test verifies that "-Z trace-macros" works as it should. The traditional -# "hello world" program provides a small example of this as not only println! is -# listed, but also print! (since println! expands to this) - --include ../tools.mk - -all: - $(RUSTC) -Z trace-macros hello.rs > $(TMPDIR)/hello.out - diff -u $(TMPDIR)/hello.out hello.trace diff --git a/src/test/run-make/trace-macros-flag/hello.trace b/src/test/run-make/trace-macros-flag/hello.trace deleted file mode 100644 index cf733339eadf..000000000000 --- a/src/test/run-make/trace-macros-flag/hello.trace +++ /dev/null @@ -1,2 +0,0 @@ -println! { "Hello, World!" } -print! { concat ! ( "Hello, World!" , "\n" ) } diff --git a/src/test/run-make/trace-macros-flag/hello.rs b/src/test/ui/macros/trace-macro.rs similarity index 100% rename from src/test/run-make/trace-macros-flag/hello.rs rename to src/test/ui/macros/trace-macro.rs diff --git a/src/test/ui/macros/trace-macro.stderr b/src/test/ui/macros/trace-macro.stderr new file mode 100644 index 000000000000..8f091ef94554 --- /dev/null +++ b/src/test/ui/macros/trace-macro.stderr @@ -0,0 +1,14 @@ +note: trace_macro + --> $DIR/trace-macro.rs:12:5 + | +12 | println!("Hello, World!"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `println! { "Hello, World!" }` + +note: trace_macro + --> $DIR/trace-macro.rs:12:5 + | +12 | println!("Hello, World!"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `print! { concat ! ( "Hello, World!" , "\n" ) }` + | + = note: this error originates in a macro outside of the current crate +