about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2016-01-21 22:14:09 +0100
committerFlorian Hahn <flo@fhahn.com>2016-01-26 10:31:54 +0100
commitb285ebc48ee7f342ca5a83e8b030359ab84e9ea0 (patch)
treeec9961b9ac6b29208b919c83a3f6e312c5d7d141 /src/libsyntax
parentfaf6d1e87391b25196b35909c3c95e5d873cacf0 (diff)
downloadrust-b285ebc48ee7f342ca5a83e8b030359ab84e9ea0.tar.gz
rust-b285ebc48ee7f342ca5a83e8b030359ab84e9ea0.zip
Update expression span when transcribing macro args
closes #29084
closes #28308
closes #25385
closes #28288
closes #31011
closes #26480
closes #26093
closes #26094
closes #25386
closes #26237
closes #25793
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 8878c606d6a..c048547f5c9 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -10,12 +10,13 @@
 use self::LockstepIterSize::*;
 
 use ast;
+use ptr;
 use ast::{TokenTree, Ident, Name};
 use codemap::{Span, DUMMY_SP};
 use errors::Handler;
 use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
 use parse::token::{DocComment, MatchNt, SubstNt};
-use parse::token::{Token, NtIdent, SpecialMacroVar};
+use parse::token::{Token, NtIdent, NtExpr, SpecialMacroVar};
 use parse::token;
 use parse::lexer::TokenAndSpan;
 
@@ -173,6 +174,11 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
     }
 }
 
+fn update_span(base: Span, expr: &mut ast::Expr) {
+    expr.span.lo = base.lo;
+    expr.span.hi = base.hi;
+}
+
 /// Return the next token from the TtReader.
 /// EFFECT: advances the reader's token field
 pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
@@ -279,6 +285,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
             }
             // FIXME #2887: think about span stuff here
             TokenTree::Token(sp, SubstNt(ident, namep)) => {
+                //println!("SubstNt {:?} {:?}", ident, sp);
                 r.stack.last_mut().unwrap().idx += 1;
                 match lookup_cur_matched(r, ident) {
                     None => {
@@ -293,10 +300,18 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
                             // (a) idents can be in lots of places, so it'd be a pain
                             // (b) we actually can, since it's a token.
                             MatchedNonterminal(NtIdent(ref sn, b)) => {
-                                r.cur_span = sn.span;
+                                r.cur_span = sp;
                                 r.cur_tok = token::Ident(sn.node, b);
                                 return ret_val;
                             }
+                            MatchedNonterminal(NtExpr(ref expr)) => {
+                                let mut expr = (**expr).clone();
+                                update_span(sp, &mut expr);
+                                // FIXME(pcwalton): Bad copy.
+                                r.cur_span = sp;
+                                r.cur_tok = token::Interpolated(NtExpr(ptr::P(expr)));
+                                return ret_val;
+                            }
                             MatchedNonterminal(ref other_whole_nt) => {
                                 // FIXME(pcwalton): Bad copy.
                                 r.cur_span = sp;