Skip to content

Commit 5641144

Browse files
committed
Use diagnostics for trace_macro instead of println
1 parent 96e2c34 commit 5641144

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/librustc_errors/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ impl Handler {
388388
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
389389
self.emit(&sp.into(), msg, Note);
390390
}
391+
pub fn span_label_without_error(&self, sp: Span, msg: &str, lbl: &str) {
392+
let mut db = DiagnosticBuilder::new(self, Note, msg);
393+
db.set_span(sp);
394+
db.span_label(sp, &lbl);
395+
db.emit();
396+
}
391397
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
392398
self.span_bug(sp, &format!("unimplemented {}", msg));
393399
}

src/libsyntax/ext/base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,9 @@ impl<'a> ExtCtxt<'a> {
765765
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
766766
self.parse_sess.span_diagnostic.span_bug(sp, msg);
767767
}
768+
pub fn span_label_without_error(&self, sp: Span, msg: &str, label: &str) {
769+
self.parse_sess.span_diagnostic.span_label_without_error(sp, msg, label);
770+
}
768771
pub fn bug(&self, msg: &str) -> ! {
769772
self.parse_sess.span_diagnostic.bug(msg);
770773
}

src/libsyntax/ext/tt/macro_rules.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
9393
rhses: &[quoted::TokenTree])
9494
-> Box<MacResult+'cx> {
9595
if cx.trace_macros() {
96-
println!("{}! {{ {} }}", name, arg);
96+
cx.span_label_without_error(sp,
97+
&"trace_macro",
98+
&format!("expands to `{}! {{ {} }}`", name, arg));
9799
}
98100

99101
// Which arm's failure should we report? (the one furthest along)

src/test/run-make/trace-macros-flag/Makefile

-9
This file was deleted.

src/test/run-make/trace-macros-flag/hello.trace

-2
This file was deleted.

src/test/ui/macros/trace-macro.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
note: trace_macro
2+
--> $DIR/trace-macro.rs:12:5
3+
|
4+
12 | println!("Hello, World!");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `println! { "Hello, World!" }`
6+
7+
note: trace_macro
8+
--> $DIR/trace-macro.rs:12:5
9+
|
10+
12 | println!("Hello, World!");
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to `print! { concat ! ( "Hello, World!" , "\n" ) }`
12+
|
13+
= note: this error originates in a macro outside of the current crate
14+

0 commit comments

Comments
 (0)