about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Cartwright <caleb.cartwright@outlook.com>2021-12-20 19:44:23 -0600
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-12-21 10:55:39 -0600
commit62987562e2fbb6ea83fa20598b9e0c91bee536e3 (patch)
treebe7d0bbb9e9e1582ca4847892a9f11c6141eb022
parentc8cf454173ec332acf3860863c7d2f088876e40b (diff)
downloadrust-62987562e2fbb6ea83fa20598b9e0c91bee536e3.tar.gz
rust-62987562e2fbb6ea83fa20598b9e0c91bee536e3.zip
refactor: extract final rustc_parse touchpoint from macros.rs
-rw-r--r--src/macros.rs5
-rw-r--r--src/parse/macros/mod.rs10
2 files changed, 11 insertions, 4 deletions
diff --git a/src/macros.rs b/src/macros.rs
index b14b67f2a0a..f29552caf8d 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -29,7 +29,7 @@ use crate::expr::{rewrite_array, rewrite_assign_rhs, RhsAssignKind};
 use crate::lists::{itemize_list, write_list, ListFormatting};
 use crate::overflow;
 use crate::parse::macros::lazy_static::parse_lazy_static;
-use crate::parse::macros::{build_parser, parse_macro_args, ParsedMacroArgs};
+use crate::parse::macros::{parse_expr, parse_macro_args, ParsedMacroArgs};
 use crate::rewrite::{Rewrite, RewriteContext};
 use crate::shape::{Indent, Shape};
 use crate::source_map::SpanUtils;
@@ -1060,11 +1060,10 @@ 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 = build_parser(context, ts);
 
         Some(ast::Expr {
             id: ast::NodeId::root(), // dummy value
-            kind: ast::ExprKind::Try(parser.parse_expr().ok()?),
+            kind: ast::ExprKind::Try(parse_expr(context, ts)?),
             span: mac.span(), // incorrect span, but shouldn't matter too much
             attrs: ast::AttrVec::new(),
             tokens: None,
diff --git a/src/parse/macros/mod.rs b/src/parse/macros/mod.rs
index 7115302a479..414b72f2921 100644
--- a/src/parse/macros/mod.rs
+++ b/src/parse/macros/mod.rs
@@ -13,7 +13,7 @@ use crate::rewrite::{Rewrite, RewriteContext};
 
 pub(crate) mod lazy_static;
 
-pub(crate) fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser<'a> {
+fn build_parser<'a>(context: &RewriteContext<'a>, tokens: TokenStream) -> Parser<'a> {
     stream_to_parser(context.parse_sess.inner(), tokens, MACRO_ARGUMENTS)
 }
 
@@ -155,6 +155,14 @@ pub(crate) fn parse_macro_args(
     })
 }
 
+pub(crate) fn parse_expr(
+    context: &RewriteContext<'_>,
+    tokens: TokenStream,
+) -> Option<ptr::P<ast::Expr>> {
+    let mut parser = build_parser(context, tokens);
+    parser.parse_expr().ok()
+}
+
 const RUST_KW: [Symbol; 59] = [
     kw::PathRoot,
     kw::DollarCrate,