@@ -16,7 +16,8 @@ use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
16
16
use rustc_ast:: tokenstream:: { Cursor , TokenStream , TokenTree } ;
17
17
use rustc_ast:: { ast, ptr} ;
18
18
use rustc_ast_pretty:: pprust;
19
- use rustc_parse:: { new_parser_from_tts, parser:: Parser } ;
19
+ use rustc_parse:: parser:: Parser ;
20
+ use rustc_parse:: { stream_to_parser, MACRO_ARGUMENTS } ;
20
21
use rustc_span:: {
21
22
symbol:: { self , kw} ,
22
23
BytePos , Span , Symbol , DUMMY_SP ,
@@ -89,6 +90,14 @@ impl Rewrite for MacroArg {
89
90
}
90
91
}
91
92
93
+ fn build_parser < ' a > ( context : & RewriteContext < ' a > , cursor : Cursor ) -> Parser < ' a > {
94
+ stream_to_parser (
95
+ context. parse_sess . inner ( ) ,
96
+ cursor. collect ( ) ,
97
+ MACRO_ARGUMENTS ,
98
+ )
99
+ }
100
+
92
101
fn parse_macro_arg < ' a , ' b : ' a > ( parser : & ' a mut Parser < ' b > ) -> Option < MacroArg > {
93
102
macro_rules! parse_macro_arg {
94
103
( $macro_arg: ident, $parser: expr, $f: expr) => {
@@ -290,7 +299,7 @@ fn rewrite_macro_inner(
290
299
}
291
300
}
292
301
293
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
302
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
294
303
let mut arg_vec = Vec :: new ( ) ;
295
304
let mut vec_with_semi = false ;
296
305
let mut trailing_comma = false ;
@@ -1196,7 +1205,7 @@ pub(crate) fn convert_try_mac(
1196
1205
let path = & pprust:: path_to_string ( & mac. path ) ;
1197
1206
if path == "try" || path == "r#try" {
1198
1207
let ts = mac. args . inner_tokens ( ) ;
1199
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
1208
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
1200
1209
1201
1210
Some ( ast:: Expr {
1202
1211
id : ast:: NodeId :: root ( ) , // dummy value
@@ -1429,7 +1438,7 @@ fn format_lazy_static(
1429
1438
ts : & TokenStream ,
1430
1439
) -> Option < String > {
1431
1440
let mut result = String :: with_capacity ( 1024 ) ;
1432
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
1441
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
1433
1442
let nested_shape = shape
1434
1443
. block_indent ( context. config . tab_spaces ( ) )
1435
1444
. with_max_width ( context. config ) ;
0 commit comments