From 5297433747e5cd2c3794fd9eb88917797e5758ae Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 22 Jan 2024 01:55:49 +0000 Subject: [PATCH] Actually, just use nonterminal_may_begin_with --- src/tools/rustfmt/src/parse/macros/mod.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs index c6ee96ebb8a..a9f9ea1826a 100644 --- a/src/tools/rustfmt/src/parse/macros/mod.rs +++ b/src/tools/rustfmt/src/parse/macros/mod.rs @@ -1,4 +1,4 @@ -use rustc_ast::token::{Delimiter, TokenKind}; +use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ast, ptr}; use rustc_parse::parser::{ForceCollect, Parser, Recovery}; @@ -24,9 +24,9 @@ fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { macro_rules! parse_macro_arg { - ($macro_arg:ident, $can_begin:expr, $try_parse:expr, $then:expr) => { + ($macro_arg:ident, $nt_kind:expr, $try_parse:expr, $then:expr) => { let mut cloned_parser = (*parser).clone(); - if $can_begin(&mut cloned_parser) { + if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) { match $try_parse(&mut cloned_parser) { Ok(x) => { if parser.sess.dcx.has_errors().is_some() { @@ -48,27 +48,26 @@ macro_rules! parse_macro_arg { parse_macro_arg!( Expr, - |parser: &mut Parser<'b>| parser.token.can_begin_expr(), + NonterminalKind::Expr, |parser: &mut Parser<'b>| parser.parse_expr(), |x: ptr::P| Some(x) ); parse_macro_arg!( Ty, - |parser: &mut Parser<'b>| parser.token.can_begin_type(), + NonterminalKind::Ty, |parser: &mut Parser<'b>| parser.parse_ty(), |x: ptr::P| Some(x) ); parse_macro_arg!( Pat, - // FIXME: This isn't right - |_| true, + NonterminalKind::PatParam { inferred: false }, |parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None), |x: ptr::P| Some(x) ); // `parse_item` returns `Option>`. parse_macro_arg!( Item, - |_| true, + NonterminalKind::Item, |parser: &mut Parser<'b>| parser.parse_item(ForceCollect::No), |x: Option>| x );