1
- use rustc_ast:: token:: { Delimiter , TokenKind } ;
1
+ use rustc_ast:: token:: { Delimiter , NonterminalKind , TokenKind } ;
2
2
use rustc_ast:: tokenstream:: TokenStream ;
3
3
use rustc_ast:: { ast, ptr} ;
4
4
use rustc_parse:: parser:: { ForceCollect , Parser , Recovery } ;
@@ -24,9 +24,9 @@ fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser
24
24
25
25
fn parse_macro_arg < ' a , ' b : ' a > ( parser : & ' a mut Parser < ' b > ) -> Option < MacroArg > {
26
26
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) => {
28
28
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 ) {
30
30
match $try_parse( & mut cloned_parser) {
31
31
Ok ( x) => {
32
32
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> {
48
48
49
49
parse_macro_arg ! (
50
50
Expr ,
51
- |parser : & mut Parser < ' b>| parser . token . can_begin_expr ( ) ,
51
+ NonterminalKind :: Expr ,
52
52
|parser: & mut Parser <' b>| parser. parse_expr( ) ,
53
53
|x: ptr:: P <ast:: Expr >| Some ( x)
54
54
) ;
55
55
parse_macro_arg ! (
56
56
Ty ,
57
- |parser : & mut Parser < ' b>| parser . token . can_begin_type ( ) ,
57
+ NonterminalKind :: Ty ,
58
58
|parser: & mut Parser <' b>| parser. parse_ty( ) ,
59
59
|x: ptr:: P <ast:: Ty >| Some ( x)
60
60
) ;
61
61
parse_macro_arg ! (
62
62
Pat ,
63
- // FIXME: This isn't right
64
- |_| true ,
63
+ NonterminalKind :: PatParam { inferred: false } ,
65
64
|parser: & mut Parser <' b>| parser. parse_pat_no_top_alt( None , None ) ,
66
65
|x: ptr:: P <ast:: Pat >| Some ( x)
67
66
) ;
68
67
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
69
68
parse_macro_arg ! (
70
69
Item ,
71
- |_| true ,
70
+ NonterminalKind :: Item ,
72
71
|parser: & mut Parser <' b>| parser. parse_item( ForceCollect :: No ) ,
73
72
|x: Option <ptr:: P <ast:: Item >>| x
74
73
) ;
0 commit comments