Skip to content

Commit 06410ef

Browse files
committed
Auto merge of #21158 - alkor:issue-21131, r=nick29581
Closes #21131
2 parents a530cc9 + 8a22454 commit 06410ef

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use self::TokenTreeOrTokenTreeVec::*;
8383
use ast;
8484
use ast::{TokenTree, Ident};
8585
use ast::{TtDelimited, TtSequence, TtToken};
86-
use codemap::{BytePos, mk_sp};
86+
use codemap::{BytePos, mk_sp, Span};
8787
use codemap;
8888
use parse::lexer::*; //resolve bug?
8989
use parse::ParseSess;
@@ -483,11 +483,11 @@ pub fn parse(sess: &ParseSess,
483483

484484
let mut ei = bb_eis.pop().unwrap();
485485
match ei.top_elts.get_tt(ei.idx) {
486-
TtToken(_, MatchNt(_, name, _, _)) => {
486+
TtToken(span, MatchNt(_, name, _, _)) => {
487487
let name_string = token::get_ident(name);
488488
let match_cur = ei.match_cur;
489489
(&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal(
490-
parse_nt(&mut rust_parser, name_string.get()))));
490+
parse_nt(&mut rust_parser, span, name_string.get()))));
491491
ei.idx += 1us;
492492
ei.match_cur += 1;
493493
}
@@ -505,7 +505,7 @@ pub fn parse(sess: &ParseSess,
505505
}
506506
}
507507

508-
pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal {
508+
pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
509509
match name {
510510
"tt" => {
511511
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 {
541541
}
542542
"meta" => token::NtMeta(p.parse_meta_item()),
543543
_ => {
544-
p.fatal(&format!("unsupported builtin nonterminal parser: {}", name)[])
544+
p.span_fatal_help(sp,
545+
&format!("invalid fragment specifier `{}`", name)[],
546+
"valid fragment specifiers are `ident`, `block`, \
547+
`stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt` \
548+
and `item`")
545549
}
546550
}
547551
}

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result<bool, String> {
457457
// harmless
458458
Ok(true)
459459
},
460-
_ => Err(format!("unrecognized builtin nonterminal `{}`", frag))
460+
_ => Err(format!("invalid fragment specifier `{}`", frag))
461461
}
462462
}
463463
}

src/test/compile-fail/issue-21356.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
macro_rules! test { ($wrong:t_ty ..) => () }
12-
//~^ ERROR: unrecognized builtin nonterminal `t_ty`
12+
//~^ ERROR: invalid fragment specifier `t_ty`
1313

1414
fn main() {}

0 commit comments

Comments
 (0)