diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d115f2ed620..9d5be3fff61 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -83,7 +83,7 @@ use self::TokenTreeOrTokenTreeVec::*; use ast; use ast::{TokenTree, Ident}; use ast::{TtDelimited, TtSequence, TtToken}; -use codemap::{BytePos, mk_sp}; +use codemap::{BytePos, mk_sp, Span}; use codemap; use parse::lexer::*; //resolve bug? use parse::ParseSess; @@ -483,11 +483,11 @@ pub fn parse(sess: &ParseSess, let mut ei = bb_eis.pop().unwrap(); match ei.top_elts.get_tt(ei.idx) { - TtToken(_, MatchNt(_, name, _, _)) => { + TtToken(span, MatchNt(_, name, _, _)) => { let name_string = token::get_ident(name); let match_cur = ei.match_cur; (&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal( - parse_nt(&mut rust_parser, name_string.get())))); + parse_nt(&mut rust_parser, span, name_string.get())))); ei.idx += 1us; ei.match_cur += 1; } @@ -505,7 +505,7 @@ pub fn parse(sess: &ParseSess, } } -pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal { +pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal { match name { "tt" => { p.quote_depth += 1us; //but in theory, non-quoted tts might be useful @@ -541,7 +541,11 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal { } "meta" => token::NtMeta(p.parse_meta_item()), _ => { - p.fatal(&format!("unsupported builtin nonterminal parser: {}", name)[]) + p.span_fatal_help(sp, + &format!("invalid fragment specifier `{}`", name)[], + "valid fragment specifiers are `ident`, `block`, \ + `stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt` \ + and `item`") } } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 8350e0222ef..666281ac6b6 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -457,7 +457,7 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result { // harmless Ok(true) }, - _ => Err(format!("unrecognized builtin nonterminal `{}`", frag)) + _ => Err(format!("invalid fragment specifier `{}`", frag)) } } } diff --git a/src/test/compile-fail/issue-21356.rs b/src/test/compile-fail/issue-21356.rs index 979534ab30c..fefd432e229 100644 --- a/src/test/compile-fail/issue-21356.rs +++ b/src/test/compile-fail/issue-21356.rs @@ -9,6 +9,6 @@ // except according to those terms. macro_rules! test { ($wrong:t_ty ..) => () } - //~^ ERROR: unrecognized builtin nonterminal `t_ty` + //~^ ERROR: invalid fragment specifier `t_ty` fn main() {}