Skip to content

Commit

Permalink
Auto merge of #33749 - jseyfried:fix_call_site_span, r=nrc
Browse files Browse the repository at this point in the history
Fix macro call site spans

Fix macro call site spans.
r? @nrc
  • Loading branch information
bors authored Jun 14, 2016
2 parents 6551acc + 2477341 commit bf84f4e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 37 deletions.
16 changes: 0 additions & 16 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,22 +617,6 @@ impl<'a> ExtCtxt<'a> {
}
pub fn backtrace(&self) -> ExpnId { self.backtrace }

/// Original span that caused the current exapnsion to happen.
pub fn original_span(&self) -> Span {
let mut expn_id = self.backtrace;
let mut call_site = None;
loop {
match self.codemap().with_expn_info(expn_id, |ei| ei.map(|ei| ei.call_site)) {
None => break,
Some(cs) => {
call_site = Some(cs);
expn_id = cs.expn_id;
}
}
}
call_site.expect("missing expansion backtrace")
}

/// Returns span for the macro which originally caused the current expansion to happen.
///
/// Stops backtracing at include! boundary.
Expand Down
8 changes: 1 addition & 7 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,8 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
},
});

// 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 mac_span = fld.cx.original_span();

let marked_tts = mark_tts(&tts[..], mark);
Some(expandfun.expand(fld.cx, mac_span, &marked_tts))
Some(expandfun.expand(fld.cx, call_site, &marked_tts))
}

IdentTT(ref expander, tt_span, allow_internal_unstable) => {
Expand Down
22 changes: 22 additions & 0 deletions src/test/compile-fail/bad-format-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 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.

// error-pattern: requires at least a format string argument
// error-pattern: bad-format-args.rs:19:5: 19:15 note: in this expansion

// error-pattern: expected token: `,`
// error-pattern: bad-format-args.rs:20:5: 20:19 note: in this expansion
// error-pattern: bad-format-args.rs:21:5: 21:22 note: in this expansion

fn main() {
format!();
format!("" 1);
format!("", 1 1);
}
4 changes: 0 additions & 4 deletions src/test/compile-fail/ifmt-bad-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ fn main() {

format!("foo } bar"); //~ ERROR: unmatched `}` found
format!("foo }"); //~ ERROR: unmatched `}` found

format!(); //~ ERROR: requires at least a format string argument
format!("" 1); //~ ERROR: expected token: `,`
format!("", 1 1); //~ ERROR: expected token: `,`
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/macro-backtrace-println.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ macro_rules! myprint {
}

macro_rules! myprintln {
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ NOTE in this expansion of myprint!
//~^ NOTE in this expansion of concat!
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ ERROR invalid reference to argument `0`
//~| NOTE in this expansion of concat!
//~| NOTE in this expansion of myprint!
}

fn main() {
myprintln!("{}"); //~ ERROR invalid reference to argument `0`
//~^ NOTE in this expansion of
myprintln!("{}"); //~ NOTE in this expansion of
}
1 change: 0 additions & 1 deletion src/test/compile-fail/macros-nonfatal-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn main() {

foo::blah!(); //~ ERROR

format!(); //~ ERROR
format!(invalid); //~ ERROR

include!(invalid); //~ ERROR
Expand Down
5 changes: 3 additions & 2 deletions src/test/compile-fail/trace_macros-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ fn main() {
// of the below being caught.

macro_rules! expando {
($x: ident) => { trace_macros!($x) }
($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable
}

expando!(true); //~ ERROR `trace_macros` is not stable
expando!(true); //~ NOTE in this expansion
//~^ NOTE in this expansion
}
8 changes: 5 additions & 3 deletions src/test/debuginfo/function-arg-initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
#![omit_gdb_pretty_printer_section]

fn immediate_args(a: isize, b: bool, c: f64) {
println!("") // #break
zzz(); // #break
}

struct BigStruct {
Expand All @@ -243,7 +243,7 @@ struct BigStruct {
}

fn non_immediate_args(a: BigStruct, b: BigStruct) {
println!("") // #break
zzz(); // #break
}

fn binding(a: i64, b: u64, c: f64) {
Expand All @@ -257,7 +257,7 @@ fn assignment(mut a: u64, b: u64, c: f64) {
}

fn function_call(x: u64, y: u64, z: f64) {
println!("Hi!") // #break
zzz(); // #break
}

fn identifier(x: u64, y: u64, z: f64) -> u64 {
Expand Down Expand Up @@ -333,3 +333,5 @@ fn main() {
while_expr(40, 41, 42);
loop_expr(43, 44, 45);
}

fn zzz() {()}

0 comments on commit bf84f4e

Please sign in to comment.