Skip to content

Commit

Permalink
Pass a more proper span to the syntax expanders
Browse files Browse the repository at this point in the history
Closes #5794
  • Loading branch information
alexcrichton committed Sep 14, 2013
1 parent 7c8f503 commit 6c4c5f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
_ => {
Expand Down
13 changes: 13 additions & 0 deletions src/test/compile-fail/debug-correct-span.rs
Original file line number Diff line number Diff line change
@@ -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
}

5 comments on commit 6c4c5f5

@bors
Copy link
Contributor

@bors bors commented on 6c4c5f5 Sep 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at alexcrichton@6c4c5f5

@bors
Copy link
Contributor

@bors bors commented on 6c4c5f5 Sep 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/issue-5794 = 6c4c5f5 into auto

@bors
Copy link
Contributor

@bors bors commented on 6c4c5f5 Sep 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/issue-5794 = 6c4c5f5 merged ok, testing candidate = 524c190

@bors
Copy link
Contributor

@bors bors commented on 6c4c5f5 Sep 14, 2013

@bors
Copy link
Contributor

@bors bors commented on 6c4c5f5 Sep 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 524c190

Please sign in to comment.