about summary refs log tree commit diff
path: root/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-05-31 16:20:50 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-06-04 15:39:12 -0400
commitb541d3da5d9f89407c7072f4a6d65872cf30a577 (patch)
tree090f52a1196afb99016986ef147be1b483b266bb /src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
parent3d5d0f898c2f3998e50c2180c6202f193c3acdbc (diff)
downloadrust-b541d3da5d9f89407c7072f4a6d65872cf30a577.tar.gz
rust-b541d3da5d9f89407c7072f4a6d65872cf30a577.zip
Add `-Z span-debug` to allow for easier debugging of proc macros
Currently, the `Debug` impl for `proc_macro::Span` just prints out
the byte range. This can make debugging proc macros (either as a crate
author or as a compiler developer) very frustrating, since neither the
actual filename nor the `SyntaxContext` is displayed.

This commit adds a perma-unstable flag `-Z span-debug`. When enabled,
the `Debug` impl for `proc_macro::Span` simply forwards directly to
`rustc_span::Span`. Once #72618 is merged, this will start displaying
actual line numbers.

While `Debug` impls are not subject to Rust's normal stability
guarnatees, we probably shouldn't expose any additional information on
stable until `#![feature(proc_macro_span)]` is stabilized. Otherwise,
we would be providing a 'backdoor' way to access information that's
supposed be behind unstable APIs.
Diffstat (limited to 'src/test/ui/proc-macro/debug/dump-debug-span-debug.rs')
-rw-r--r--src/test/ui/proc-macro/debug/dump-debug-span-debug.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs b/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
new file mode 100644
index 00000000000..fd34eb974c0
--- /dev/null
+++ b/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
@@ -0,0 +1,41 @@
+// run-pass
+// aux-build:macro-dump-debug.rs
+// compile-flags: -Z span-debug
+
+extern crate macro_dump_debug;
+use macro_dump_debug::dump_debug;
+
+dump_debug! {
+    ident   // ident
+    r#ident // raw ident
+    ,       // alone punct
+    ==>     // joint punct
+    ()      // empty group
+    [_]     // nonempty group
+
+    // unsuffixed literals
+    0
+    1.0
+    "S"
+    b"B"
+    r"R"
+    r##"R"##
+    br"BR"
+    br##"BR"##
+    'C'
+    b'B'
+
+    // suffixed literals
+    0q
+    1.0q
+    "S"q
+    b"B"q
+    r"R"q
+    r##"R"##q
+    br"BR"q
+    br##"BR"##q
+    'C'q
+    b'B'q
+}
+
+fn main() {}