deps: update macro parsing
This commit is contained in:
parent
d95a2875f7
commit
c89638ae55
1 changed files with 13 additions and 4 deletions
|
@ -16,7 +16,8 @@ use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
|
||||||
use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree};
|
use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree};
|
||||||
use rustc_ast::{ast, ptr};
|
use rustc_ast::{ast, ptr};
|
||||||
use rustc_ast_pretty::pprust;
|
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::{
|
use rustc_span::{
|
||||||
symbol::{self, kw},
|
symbol::{self, kw},
|
||||||
BytePos, Span, Symbol, DUMMY_SP,
|
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> {
|
fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
|
||||||
macro_rules! parse_macro_arg {
|
macro_rules! parse_macro_arg {
|
||||||
($macro_arg:ident, $parser:expr, $f:expr) => {
|
($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 arg_vec = Vec::new();
|
||||||
let mut vec_with_semi = false;
|
let mut vec_with_semi = false;
|
||||||
let mut trailing_comma = false;
|
let mut trailing_comma = false;
|
||||||
|
@ -1196,7 +1205,7 @@ pub(crate) fn convert_try_mac(
|
||||||
let path = &pprust::path_to_string(&mac.path);
|
let path = &pprust::path_to_string(&mac.path);
|
||||||
if path == "try" || path == "r#try" {
|
if path == "try" || path == "r#try" {
|
||||||
let ts = mac.args.inner_tokens();
|
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 {
|
Some(ast::Expr {
|
||||||
id: ast::NodeId::root(), // dummy value
|
id: ast::NodeId::root(), // dummy value
|
||||||
|
@ -1429,7 +1438,7 @@ fn format_lazy_static(
|
||||||
ts: &TokenStream,
|
ts: &TokenStream,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let mut result = String::with_capacity(1024);
|
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
|
let nested_shape = shape
|
||||||
.block_indent(context.config.tab_spaces())
|
.block_indent(context.config.tab_spaces())
|
||||||
.with_max_width(context.config);
|
.with_max_width(context.config);
|
||||||
|
|
Loading…
Reference in a new issue