Skip to content

Commit 6c4c5f5

Browse files
committed
Pass a more proper span to the syntax expanders
Closes #5794
1 parent 7c8f503 commit 6c4c5f5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/libsyntax/ext/expand.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,26 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
7676
// mark before:
7777
let marked_before = mark_tts(*tts,fm);
7878
let marked_ctxt = new_mark(fm, ctxt);
79+
80+
// The span that we pass to the expanders we want to
81+
// be the root of the call stack. That's the most
82+
// relevant span and it's the actual invocation of
83+
// the macro.
84+
let mut relevant_info = cx.backtrace();
85+
let mut einfo = relevant_info.unwrap();
86+
loop {
87+
match relevant_info {
88+
None => { break }
89+
Some(e) => {
90+
einfo = e;
91+
relevant_info = einfo.call_site.expn_info;
92+
}
93+
}
94+
}
95+
7996
let expanded =
80-
match expandfun(cx, mac.span, marked_before, marked_ctxt) {
97+
match expandfun(cx, einfo.call_site,
98+
marked_before, marked_ctxt) {
8199
MRExpr(e) => e,
82100
MRAny(expr_maker,_,_) => expr_maker(),
83101
_ => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
debug!("%s %s", 3); //~ ERROR: not enough arguments
13+
}

0 commit comments

Comments
 (0)