@@ -16,7 +16,8 @@ use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
1616use rustc_ast:: tokenstream:: { Cursor , TokenStream , TokenTree } ;
1717use rustc_ast:: { ast, ptr} ;
1818use 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 } ;
2021use rustc_span:: {
2122 symbol:: { self , kw} ,
2223 BytePos , Span , Symbol , DUMMY_SP ,
@@ -88,6 +89,14 @@ impl Rewrite for MacroArg {
8889 }
8990}
9091
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+
91100fn parse_macro_arg < ' a , ' b : ' a > ( parser : & ' a mut Parser < ' b > ) -> Option < MacroArg > {
92101 macro_rules! parse_macro_arg {
93102 ( $macro_arg: ident, $parser: expr, $f: expr) => {
@@ -297,7 +306,7 @@ fn rewrite_macro_inner(
297306 }
298307 }
299308
300- let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
309+ let mut parser = build_parser ( context, ts. trees ( ) ) ;
301310 let mut arg_vec = Vec :: new ( ) ;
302311 let mut vec_with_semi = false ;
303312 let mut trailing_comma = false ;
@@ -1204,7 +1213,7 @@ pub(crate) fn convert_try_mac(
12041213 let path = & pprust:: path_to_string ( & mac. path ) ;
12051214 if path == "try" || path == "r#try" {
12061215 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 ( ) ) ;
12081217
12091218 let mut kind = parser. parse_expr ( ) . ok ( ) ?;
12101219 // take the end pos of mac so that the Try expression includes the closing parenthesis of
@@ -1445,7 +1454,7 @@ fn format_lazy_static(
14451454 ts : & TokenStream ,
14461455) -> Option < String > {
14471456 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 ( ) ) ;
14491458 let nested_shape = shape
14501459 . block_indent ( context. config . tab_spaces ( ) )
14511460 . with_max_width ( context. config ) ;
0 commit comments