From 6c4c5f56313b3b48dc42297ca927f2a43715e19f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 13 Sep 2013 20:54:52 -0700 Subject: Pass a more proper span to the syntax expanders Closes #5794 --- src/libsyntax/ext/expand.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 2cebae550fd..ee62f35a4e4 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -76,8 +76,26 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, // mark before: let marked_before = mark_tts(*tts,fm); let marked_ctxt = new_mark(fm, ctxt); + + // The span that we pass to the expanders we want to + // be the root of the call stack. That's the most + // relevant span and it's the actual invocation of + // the macro. + let mut relevant_info = cx.backtrace(); + let mut einfo = relevant_info.unwrap(); + loop { + match relevant_info { + None => { break } + Some(e) => { + einfo = e; + relevant_info = einfo.call_site.expn_info; + } + } + } + let expanded = - match expandfun(cx, mac.span, marked_before, marked_ctxt) { + match expandfun(cx, einfo.call_site, + marked_before, marked_ctxt) { MRExpr(e) => e, MRAny(expr_maker,_,_) => expr_maker(), _ => { -- cgit 1.4.1-3-g733a5