Skip to content

Commit c89638a

Browse files
deps: update macro parsing
1 parent d95a287 commit c89638a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/macros.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
1616
use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree};
1717
use rustc_ast::{ast, ptr};
1818
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};
2021
use rustc_span::{
2122
symbol::{self, kw},
2223
BytePos, Span, Symbol, DUMMY_SP,
@@ -89,6 +90,14 @@ impl Rewrite for MacroArg {
8990
}
9091
}
9192

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+
92101
fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
93102
macro_rules! parse_macro_arg {
94103
($macro_arg:ident, $parser:expr, $f:expr) => {
@@ -290,7 +299,7 @@ fn rewrite_macro_inner(
290299
}
291300
}
292301

293-
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
302+
let mut parser = build_parser(context, ts.trees());
294303
let mut arg_vec = Vec::new();
295304
let mut vec_with_semi = false;
296305
let mut trailing_comma = false;
@@ -1196,7 +1205,7 @@ pub(crate) fn convert_try_mac(
11961205
let path = &pprust::path_to_string(&mac.path);
11971206
if path == "try" || path == "r#try" {
11981207
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());
12001209

12011210
Some(ast::Expr {
12021211
id: ast::NodeId::root(), // dummy value
@@ -1429,7 +1438,7 @@ fn format_lazy_static(
14291438
ts: &TokenStream,
14301439
) -> Option<String> {
14311440
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());
14331442
let nested_shape = shape
14341443
.block_indent(context.config.tab_spaces())
14351444
.with_max_width(context.config);

0 commit comments

Comments
 (0)