deps: update macro parsing
This commit is contained in:
parent
d95a2875f7
commit
c89638ae55
@ -16,7 +16,8 @@ use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree};
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_parse::{new_parser_from_tts, parser::Parser};
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_parse::{stream_to_parser, MACRO_ARGUMENTS};
|
||||
use rustc_span::{
|
||||
symbol::{self, kw},
|
||||
BytePos, Span, Symbol, DUMMY_SP,
|
||||
@ -89,6 +90,14 @@ impl Rewrite for MacroArg {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_parser<'a>(context: &RewriteContext<'a>, cursor: Cursor) -> Parser<'a> {
|
||||
stream_to_parser(
|
||||
context.parse_sess.inner(),
|
||||
cursor.collect(),
|
||||
MACRO_ARGUMENTS,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
|
||||
macro_rules! parse_macro_arg {
|
||||
($macro_arg:ident, $parser:expr, $f:expr) => {
|
||||
@ -290,7 +299,7 @@ fn rewrite_macro_inner(
|
||||
}
|
||||
}
|
||||
|
||||
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
|
||||
let mut parser = build_parser(context, ts.trees());
|
||||
let mut arg_vec = Vec::new();
|
||||
let mut vec_with_semi = false;
|
||||
let mut trailing_comma = false;
|
||||
@ -1196,7 +1205,7 @@ pub(crate) fn convert_try_mac(
|
||||
let path = &pprust::path_to_string(&mac.path);
|
||||
if path == "try" || path == "r#try" {
|
||||
let ts = mac.args.inner_tokens();
|
||||
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
|
||||
let mut parser = build_parser(context, ts.trees());
|
||||
|
||||
Some(ast::Expr {
|
||||
id: ast::NodeId::root(), // dummy value
|
||||
@ -1429,7 +1438,7 @@ fn format_lazy_static(
|
||||
ts: &TokenStream,
|
||||
) -> Option<String> {
|
||||
let mut result = String::with_capacity(1024);
|
||||
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
|
||||
let mut parser = build_parser(context, ts.trees());
|
||||
let nested_shape = shape
|
||||
.block_indent(context.config.tab_spaces())
|
||||
.with_max_width(context.config);
|
||||
|
Loading…
x
Reference in New Issue
Block a user