Skip to content

Commit

Permalink
Use diagnostics for trace_macro instead of println
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed May 5, 2017
1 parent 96e2c34 commit 5641144
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/librustc_errors/lib.rs
Expand Up @@ -388,6 +388,12 @@ impl Handler {
pub fn span_note_without_error<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
self.span_bug(sp, &format!("unimplemented {}", msg));
}
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/ext/base.rs
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Expand Up @@ -93,7 +93,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
rhses: &[quoted::TokenTree])
-> Box<MacResult+'cx> {
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)
Expand Down
9 changes: 0 additions & 9 deletions src/test/run-make/trace-macros-flag/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/run-make/trace-macros-flag/hello.trace

This file was deleted.

File renamed without changes.
14 changes: 14 additions & 0 deletions 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

0 comments on commit 5641144

Please sign in to comment.