From 63f927311a319b920cdb2262fd7176ec8ffe619c Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 19 May 2016 11:31:41 +0000 Subject: [PATCH 1/2] Fix macro call site spans --- src/libsyntax/ext/base.rs | 16 ---------------- src/libsyntax/ext/expand.rs | 9 ++------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 303187aeba87d..57c7a3ddc2fc2 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -602,22 +602,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. diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 596faac35882a..38c262b857a35 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -215,6 +215,7 @@ fn expand_mac_invoc(mac: ast::Mac, ident: Option, attrs: Vec { @@ -234,14 +235,8 @@ fn expand_mac_invoc(mac: ast::Mac, ident: Option, attrs: Vec { From e77a21952a3e2c542377494d70ab3abca2d1d2b2 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 19 May 2016 22:28:14 +0000 Subject: [PATCH 2/2] Fix fallout in tests --- src/test/compile-fail/bad-format-args.rs | 22 +++++++++++++++++++ src/test/compile-fail/ifmt-bad-arg.rs | 4 ---- .../compile-fail/macro-backtrace-println.rs | 8 +++---- .../compile-fail/macros-nonfatal-errors.rs | 1 - src/test/compile-fail/trace_macros-gate.rs | 5 +++-- 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/test/compile-fail/bad-format-args.rs diff --git a/src/test/compile-fail/bad-format-args.rs b/src/test/compile-fail/bad-format-args.rs new file mode 100644 index 0000000000000..816c696a89566 --- /dev/null +++ b/src/test/compile-fail/bad-format-args.rs @@ -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 or the MIT license +// , 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); +} diff --git a/src/test/compile-fail/ifmt-bad-arg.rs b/src/test/compile-fail/ifmt-bad-arg.rs index 7c929d2db16e7..1368702b160bf 100644 --- a/src/test/compile-fail/ifmt-bad-arg.rs +++ b/src/test/compile-fail/ifmt-bad-arg.rs @@ -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: `,` } diff --git a/src/test/compile-fail/macro-backtrace-println.rs b/src/test/compile-fail/macro-backtrace-println.rs index c2277c3e6d8cd..9d6da2a53a222 100644 --- a/src/test/compile-fail/macro-backtrace-println.rs +++ b/src/test/compile-fail/macro-backtrace-println.rs @@ -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 } diff --git a/src/test/compile-fail/macros-nonfatal-errors.rs b/src/test/compile-fail/macros-nonfatal-errors.rs index 42a0f41dd97c3..723e936212a5b 100644 --- a/src/test/compile-fail/macros-nonfatal-errors.rs +++ b/src/test/compile-fail/macros-nonfatal-errors.rs @@ -32,7 +32,6 @@ fn main() { foo::blah!(); //~ ERROR - format!(); //~ ERROR format!(invalid); //~ ERROR include!(invalid); //~ ERROR diff --git a/src/test/compile-fail/trace_macros-gate.rs b/src/test/compile-fail/trace_macros-gate.rs index d627de24d6794..e9b7ddf6d1c6c 100644 --- a/src/test/compile-fail/trace_macros-gate.rs +++ b/src/test/compile-fail/trace_macros-gate.rs @@ -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 }