diff options
| author | bors <bors@rust-lang.org> | 2015-08-11 23:21:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-08-11 23:21:19 +0000 |
| commit | 58b0aa5e420643d454cf141263652a8bcb6a35f1 (patch) | |
| tree | 8f03280953abf3c01c9b07da94deb3b7dd57543b /src/libsyntax | |
| parent | dcdcc6f6bcfc418fd828dcdc3f792d9b4edbb658 (diff) | |
| parent | d46e84081f88f22198fbfcd5221faaf922e0500d (diff) | |
| download | rust-58b0aa5e420643d454cf141263652a8bcb6a35f1.tar.gz rust-58b0aa5e420643d454cf141263652a8bcb6a35f1.zip | |
Auto merge of #27584 - TimNN:macro-eof-span, r=huonw
The ideas is to use the span of the complete macro invocation if the span of a macro error is `DUMMY_SP`. fixes #7970
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 24 |
3 files changed, 24 insertions, 23 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 17e6b2c2e12..0aeb572b6bc 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -135,6 +135,13 @@ pub const COMMAND_LINE_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: COMMAND_LINE_EXPN }; +impl Span { + /// Returns `self` if `self` is not the dummy span, and `other` otherwise. + pub fn substitute_dummy(self, other: Span) -> Span { + if self == DUMMY_SP { other } else { self } + } +} + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub struct Spanned<T> { pub node: T, diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4556bd5f8e5..26b4181ea8a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -249,22 +249,6 @@ pub enum ParseResult<T> { pub type NamedParseResult = ParseResult<HashMap<Ident, Rc<NamedMatch>>>; pub type PositionalParseResult = ParseResult<Vec<Rc<NamedMatch>>>; -pub fn parse_or_else(sess: &ParseSess, - cfg: ast::CrateConfig, - rdr: TtReader, - ms: Vec<TokenTree> ) - -> HashMap<Ident, Rc<NamedMatch>> { - match parse(sess, cfg, rdr, &ms[..]) { - Success(m) => m, - Failure(sp, str) => { - panic!(sess.span_diagnostic.span_fatal(sp, &str[..])) - } - Error(sp, str) => { - panic!(sess.span_diagnostic.span_fatal(sp, &str[..])) - } - } -} - /// Perform a token equality check, ignoring syntax context (that is, an /// unhygienic comparison) pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index d16fde7bc39..d728fa59bd1 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -14,7 +14,7 @@ use ext::base::{ExtCtxt, MacResult, SyntaxExtension}; use ext::base::{NormalTT, TTMacroExpander}; use ext::tt::macro_parser::{Success, Error, Failure}; use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; -use ext::tt::macro_parser::{parse, parse_or_else}; +use ext::tt::macro_parser::parse; use parse::lexer::new_tt_reader; use parse::parser::Parser; use parse::token::{self, special_idents, gensym_ident, NtTT, Token}; @@ -211,13 +211,16 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, best_fail_spot = sp; best_fail_msg = (*msg).clone(); }, - Error(sp, ref msg) => panic!(cx.span_fatal(sp, &msg[..])) + Error(err_sp, ref msg) => { + panic!(cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..])) + } } } _ => cx.bug("non-matcher found in parsed lhses") } } - panic!(cx.span_fatal(best_fail_spot, &best_fail_msg[..])); + + panic!(cx.span_fatal(best_fail_spot.substitute_dummy(sp), &best_fail_msg[..])); } // Note that macro-by-example's input is also matched against a token tree: @@ -266,10 +269,17 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, None, None, def.body.clone()); - let argument_map = parse_or_else(cx.parse_sess(), - cx.cfg(), - arg_reader, - argument_gram); + + let argument_map = match parse(cx.parse_sess(), + cx.cfg(), + arg_reader, + &argument_gram) { + Success(m) => m, + Failure(sp, str) | Error(sp, str) => { + panic!(cx.parse_sess().span_diagnostic + .span_fatal(sp.substitute_dummy(def.span), &str[..])); + } + }; // Extract the arguments: let lhses = match **argument_map.get(&lhs_nm).unwrap() { |
