about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-09-13 20:54:52 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-09-13 20:54:52 -0700
commit6c4c5f56313b3b48dc42297ca927f2a43715e19f (patch)
treef028f5ee9d5b1578c7f388dc50e00f724fb3d7d9
parent7c8f503ac543e0ffe18986b8d6f8548df21cefa3 (diff)
downloadrust-6c4c5f56313b3b48dc42297ca927f2a43715e19f.tar.gz
rust-6c4c5f56313b3b48dc42297ca927f2a43715e19f.zip
Pass a more proper span to the syntax expanders
Closes #5794
-rw-r--r--src/libsyntax/ext/expand.rs20
-rw-r--r--src/test/compile-fail/debug-correct-span.rs13
2 files changed, 32 insertions, 1 deletions
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(),
                                     _ => {
diff --git a/src/test/compile-fail/debug-correct-span.rs b/src/test/compile-fail/debug-correct-span.rs
new file mode 100644
index 00000000000..f143e6c00a2
--- /dev/null
+++ b/src/test/compile-fail/debug-correct-span.rs
@@ -0,0 +1,13 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    debug!("%s %s", 3); //~ ERROR: not enough arguments
+}