@@ -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 ,
@@ -88,6 +89,14 @@ impl Rewrite for MacroArg {
88
89
}
89
90
}
90
91
92
+ fn build_parser < ' a > ( context : & RewriteContext < ' a > , cursor : Cursor ) -> Parser < ' a > {
93
+ stream_to_parser (
94
+ context. parse_sess . inner ( ) ,
95
+ cursor. collect ( ) ,
96
+ MACRO_ARGUMENTS ,
97
+ )
98
+ }
99
+
91
100
fn parse_macro_arg < ' a , ' b : ' a > ( parser : & ' a mut Parser < ' b > ) -> Option < MacroArg > {
92
101
macro_rules! parse_macro_arg {
93
102
( $macro_arg: ident, $parser: expr, $f: expr) => {
@@ -297,7 +306,7 @@ fn rewrite_macro_inner(
297
306
}
298
307
}
299
308
300
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
309
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
301
310
let mut arg_vec = Vec :: new ( ) ;
302
311
let mut vec_with_semi = false ;
303
312
let mut trailing_comma = false ;
@@ -1204,7 +1213,7 @@ pub(crate) fn convert_try_mac(
1204
1213
let path = & pprust:: path_to_string ( & mac. path ) ;
1205
1214
if path == "try" || path == "r#try" {
1206
1215
let ts = mac. args . inner_tokens ( ) ;
1207
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
1216
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
1208
1217
1209
1218
let mut kind = parser. parse_expr ( ) . ok ( ) ?;
1210
1219
// take the end pos of mac so that the Try expression includes the closing parenthesis of
@@ -1445,7 +1454,7 @@ fn format_lazy_static(
1445
1454
ts : & TokenStream ,
1446
1455
) -> Option < String > {
1447
1456
let mut result = String :: with_capacity ( 1024 ) ;
1448
- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
1457
+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
1449
1458
let nested_shape = shape
1450
1459
. block_indent ( context. config . tab_spaces ( ) )
1451
1460
. with_max_width ( context. config ) ;
0 commit comments