Skip to content

Commit bf84f4e

Browse files
authored
Auto merge of #33749 - jseyfried:fix_call_site_span, r=nrc
Fix macro call site spans Fix macro call site spans. r? @nrc
2 parents 6551acc + 2477341 commit bf84f4e

8 files changed

+35
-37
lines changed

src/libsyntax/ext/base.rs

-16
Original file line numberDiff line numberDiff line change
@@ -617,22 +617,6 @@ impl<'a> ExtCtxt<'a> {
617617
}
618618
pub fn backtrace(&self) -> ExpnId { self.backtrace }
619619

620-
/// Original span that caused the current exapnsion to happen.
621-
pub fn original_span(&self) -> Span {
622-
let mut expn_id = self.backtrace;
623-
let mut call_site = None;
624-
loop {
625-
match self.codemap().with_expn_info(expn_id, |ei| ei.map(|ei| ei.call_site)) {
626-
None => break,
627-
Some(cs) => {
628-
call_site = Some(cs);
629-
expn_id = cs.expn_id;
630-
}
631-
}
632-
}
633-
call_site.expect("missing expansion backtrace")
634-
}
635-
636620
/// Returns span for the macro which originally caused the current expansion to happen.
637621
///
638622
/// Stops backtracing at include! boundary.

src/libsyntax/ext/expand.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,8 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
236236
},
237237
});
238238

239-
// The span that we pass to the expanders we want to
240-
// be the root of the call stack. That's the most
241-
// relevant span and it's the actual invocation of
242-
// the macro.
243-
let mac_span = fld.cx.original_span();
244-
245239
let marked_tts = mark_tts(&tts[..], mark);
246-
Some(expandfun.expand(fld.cx, mac_span, &marked_tts))
240+
Some(expandfun.expand(fld.cx, call_site, &marked_tts))
247241
}
248242

249243
IdentTT(ref expander, tt_span, allow_internal_unstable) => {
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 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+
// error-pattern: requires at least a format string argument
12+
// error-pattern: bad-format-args.rs:19:5: 19:15 note: in this expansion
13+
14+
// error-pattern: expected token: `,`
15+
// error-pattern: bad-format-args.rs:20:5: 20:19 note: in this expansion
16+
// error-pattern: bad-format-args.rs:21:5: 21:22 note: in this expansion
17+
18+
fn main() {
19+
format!();
20+
format!("" 1);
21+
format!("", 1 1);
22+
}

src/test/compile-fail/ifmt-bad-arg.rs

-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,4 @@ fn main() {
5050

5151
format!("foo } bar"); //~ ERROR: unmatched `}` found
5252
format!("foo }"); //~ ERROR: unmatched `}` found
53-
54-
format!(); //~ ERROR: requires at least a format string argument
55-
format!("" 1); //~ ERROR: expected token: `,`
56-
format!("", 1 1); //~ ERROR: expected token: `,`
5753
}

src/test/compile-fail/macro-backtrace-println.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ macro_rules! myprint {
2121
}
2222

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

2829
fn main() {
29-
myprintln!("{}"); //~ ERROR invalid reference to argument `0`
30-
//~^ NOTE in this expansion of
30+
myprintln!("{}"); //~ NOTE in this expansion of
3131
}

src/test/compile-fail/macros-nonfatal-errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fn main() {
3232

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

35-
format!(); //~ ERROR
3635
format!(invalid); //~ ERROR
3736

3837
include!(invalid); //~ ERROR

src/test/compile-fail/trace_macros-gate.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ fn main() {
2323
// of the below being caught.
2424

2525
macro_rules! expando {
26-
($x: ident) => { trace_macros!($x) }
26+
($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable
2727
}
2828

29-
expando!(true); //~ ERROR `trace_macros` is not stable
29+
expando!(true); //~ NOTE in this expansion
30+
//~^ NOTE in this expansion
3031
}

src/test/debuginfo/function-arg-initialization.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
#![omit_gdb_pretty_printer_section]
229229

230230
fn immediate_args(a: isize, b: bool, c: f64) {
231-
println!("") // #break
231+
zzz(); // #break
232232
}
233233

234234
struct BigStruct {
@@ -243,7 +243,7 @@ struct BigStruct {
243243
}
244244

245245
fn non_immediate_args(a: BigStruct, b: BigStruct) {
246-
println!("") // #break
246+
zzz(); // #break
247247
}
248248

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

259259
fn function_call(x: u64, y: u64, z: f64) {
260-
println!("Hi!") // #break
260+
zzz(); // #break
261261
}
262262

263263
fn identifier(x: u64, y: u64, z: f64) -> u64 {
@@ -333,3 +333,5 @@ fn main() {
333333
while_expr(40, 41, 42);
334334
loop_expr(43, 44, 45);
335335
}
336+
337+
fn zzz() {()}

0 commit comments

Comments
 (0)