Skip to content

Commit a095808

Browse files
Actually, just use nonterminal_may_begin_with
1 parent f8847ff commit a095808

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/parse/macros/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_ast::token::{Delimiter, TokenKind};
1+
use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind};
22
use rustc_ast::tokenstream::TokenStream;
33
use rustc_ast::{ast, ptr};
44
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
@@ -24,9 +24,9 @@ fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser
2424

2525
fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
2626
macro_rules! parse_macro_arg {
27-
($macro_arg:ident, $can_begin:expr, $try_parse:expr, $then:expr) => {
27+
($macro_arg:ident, $nt_kind:expr, $try_parse:expr, $then:expr) => {
2828
let mut cloned_parser = (*parser).clone();
29-
if $can_begin(&mut cloned_parser) {
29+
if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) {
3030
match $try_parse(&mut cloned_parser) {
3131
Ok(x) => {
3232
if parser.sess.dcx.has_errors().is_some() {
@@ -48,27 +48,26 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
4848

4949
parse_macro_arg!(
5050
Expr,
51-
|parser: &mut Parser<'b>| parser.token.can_begin_expr(),
51+
NonterminalKind::Expr,
5252
|parser: &mut Parser<'b>| parser.parse_expr(),
5353
|x: ptr::P<ast::Expr>| Some(x)
5454
);
5555
parse_macro_arg!(
5656
Ty,
57-
|parser: &mut Parser<'b>| parser.token.can_begin_type(),
57+
NonterminalKind::Ty,
5858
|parser: &mut Parser<'b>| parser.parse_ty(),
5959
|x: ptr::P<ast::Ty>| Some(x)
6060
);
6161
parse_macro_arg!(
6262
Pat,
63-
// FIXME: This isn't right
64-
|_| true,
63+
NonterminalKind::PatParam { inferred: false },
6564
|parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None),
6665
|x: ptr::P<ast::Pat>| Some(x)
6766
);
6867
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
6968
parse_macro_arg!(
7069
Item,
71-
|_| true,
70+
NonterminalKind::Item,
7271
|parser: &mut Parser<'b>| parser.parse_item(ForceCollect::No),
7372
|x: Option<ptr::P<ast::Item>>| x
7473
);

0 commit comments

Comments
 (0)