about summary refs log tree commit diff
path: root/src/librustc_parse/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_parse/lib.rs')
-rw-r--r--src/librustc_parse/lib.rs27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs
index a222f3f00c4..f1967372f4d 100644
--- a/src/librustc_parse/lib.rs
+++ b/src/librustc_parse/lib.rs
@@ -270,21 +270,13 @@ pub fn stream_to_parser_with_base_dir<'a>(
 }
 
 /// Runs the given subparser `f` on the tokens of the given `attr`'s item.
-pub fn parse_in_attr<'a, T>(
+pub fn parse_in<'a, T>(
     sess: &'a ParseSess,
-    attr: &ast::Attribute,
+    tts: TokenStream,
+    name: &'static str,
     mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
 ) -> PResult<'a, T> {
-    let mut parser = Parser::new(
-        sess,
-        // FIXME(#66940, Centril | petrochenkov): refactor this function so it doesn't
-        // require reconstructing and immediately re-parsing delimiters.
-        attr.get_normal_item().args.outer_tokens(),
-        None,
-        false,
-        false,
-        Some("attribute"),
-    );
+    let mut parser = Parser::new(sess, tts, None, false, false, Some(name));
     let result = f(&mut parser)?;
     if parser.token != token::Eof {
         parser.unexpected()?;
@@ -292,6 +284,17 @@ pub fn parse_in_attr<'a, T>(
     Ok(result)
 }
 
+/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
+pub fn parse_in_attr<'a, T>(
+    sess: &'a ParseSess,
+    attr: &ast::Attribute,
+    f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
+) -> PResult<'a, T> {
+    // FIXME(#66940, Centril | petrochenkov): refactor this function so it doesn't
+    // require reconstructing and immediately re-parsing delimiters.
+    parse_in(sess, attr.get_normal_item().args.outer_tokens(), "attribute", f)
+}
+
 // NOTE(Centril): The following probably shouldn't be here but it acknowledges the
 // fact that architecturally, we are using parsing (read on below to understand why).