about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/expand.rs1
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs15
-rw-r--r--src/libsyntax/ext/tt/quoted.rs2
3 files changed, 16 insertions, 2 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index d2e51c9cb48..dc0848176d6 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1046,6 +1046,7 @@ impl<'feat> ExpansionConfig<'feat> {
 }
 
 // A Marker adds the given mark to the syntax context.
+#[derive(Debug)]
 pub struct Marker(pub Mark);
 
 impl Folder for Marker {
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index f786b1abb8a..c7aab95e1d4 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -119,8 +119,21 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
                     quoted::TokenTree::Delimited(_, ref delimed) => delimed.tts.clone(),
                     _ => cx.span_bug(sp, "malformed macro rhs"),
                 };
+
                 // rhs has holes ( `$id` and `$(...)` that need filled)
-                let tts = transcribe(cx, Some(named_matches), rhs);
+                let mut tts = transcribe(cx, Some(named_matches), rhs.clone());
+
+                // Replace all the tokens for the corresponding positions in the macro, to maintain
+                // proper positions in error reporting, while maintaining the macro_backtrace.
+                if rhs.len() == tts.len() {
+                    tts = tts.map_pos(|i, tt| {
+                        let mut tt = tt.clone();
+                        let mut sp = rhs[i].span();
+                        sp.ctxt = tt.span().ctxt;
+                        tt.set_span(sp);
+                        tt
+                    });
+                }
 
                 if cx.trace_macros() {
                     trace_macros_note(cx, sp, format!("to `{}`", tts));
diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs
index 74fa85d130b..6fdcadd1dde 100644
--- a/src/libsyntax/ext/tt/quoted.rs
+++ b/src/libsyntax/ext/tt/quoted.rs
@@ -128,7 +128,7 @@ impl TokenTree {
         }
     }
 
-    /// Retrieve the TokenTree's span.
+    /// Retrieve the `TokenTree`'s span.
     pub fn span(&self) -> Span {
         match *self {
             TokenTree::Token(sp, _) |