Use diagnostics for trace_macro instead of println
This commit is contained in:
parent
96e2c34286
commit
56411443f2
7 changed files with 26 additions and 12 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
println! { "Hello, World!" }
|
||||
print! { concat ! ( "Hello, World!" , "\n" ) }
|
||||
14
src/test/ui/macros/trace-macro.stderr
Normal file
14
src/test/ui/macros/trace-macro.stderr
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue