]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_expand/src/mbe/metavar_expr.rs
Remove `crate` visibility usage in compiler
[rust.git] / compiler / rustc_expand / src / mbe / metavar_expr.rs
index 52a656e1d1c14e11546cca2720bd08730873b39d..ccc1c2b2ca05b37d81b27c23b08adf4dd9d2595c 100644 (file)
@@ -1,5 +1,5 @@
-use rustc_ast::token;
-use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree};
+use rustc_ast::token::{self, Delimiter};
+use rustc_ast::tokenstream::{CursorRef, TokenStream, TokenTree};
 use rustc_ast::{LitIntType, LitKind};
 use rustc_ast_pretty::pprust;
 use rustc_errors::{Applicability, PResult};
@@ -9,7 +9,7 @@
 
 /// A meta-variable expression, for expansions based on properties of meta-variables.
 #[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
-crate enum MetaVarExpr {
+pub(crate) enum MetaVarExpr {
     /// The number of repetitions of an identifier, optionally limited to a number
     /// of outer-most repetition depths. If the depth limit is `None` then the depth is unlimited.
     Count(Ident, Option<usize>),
 
 impl MetaVarExpr {
     /// Attempt to parse a meta-variable expression from a token stream.
-    crate fn parse<'sess>(
+    pub(crate) fn parse<'sess>(
         input: &TokenStream,
         outer_span: Span,
         sess: &'sess ParseSess,
     ) -> PResult<'sess, MetaVarExpr> {
         let mut tts = input.trees();
         let ident = parse_ident(&mut tts, sess, outer_span)?;
-        let Some(TokenTree::Delimited(_, token::Paren, args)) = tts.next() else {
+        let Some(TokenTree::Delimited(_, Delimiter::Parenthesis, args)) = tts.next() else {
             let msg = "meta-variable expression parameter must be wrapped in parentheses";
             return Err(sess.span_diagnostic.struct_span_err(ident.span, msg));
         };
@@ -62,7 +62,7 @@ impl MetaVarExpr {
         Ok(rslt)
     }
 
-    crate fn ident(&self) -> Option<Ident> {
+    pub(crate) fn ident(&self) -> Option<Ident> {
         match *self {
             MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
             MetaVarExpr::Index(..) | MetaVarExpr::Length(..) => None,
@@ -71,12 +71,14 @@ impl MetaVarExpr {
 }
 
 // Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
-fn check_trailing_token<'sess>(iter: &mut Cursor, sess: &'sess ParseSess) -> PResult<'sess, ()> {
+fn check_trailing_token<'sess>(
+    iter: &mut CursorRef<'_>,
+    sess: &'sess ParseSess,
+) -> PResult<'sess, ()> {
     if let Some(tt) = iter.next() {
-        let mut diag = sess.span_diagnostic.struct_span_err(
-            tt.span(),
-            &format!("unexpected token: {}", pprust::tt_to_string(&tt)),
-        );
+        let mut diag = sess
+            .span_diagnostic
+            .struct_span_err(tt.span(), &format!("unexpected token: {}", pprust::tt_to_string(tt)));
         diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
         Err(diag)
     } else {
@@ -86,7 +88,7 @@ fn check_trailing_token<'sess>(iter: &mut Cursor, sess: &'sess ParseSess) -> PRe
 
 /// Parse a meta-variable `count` expression: `count(ident[, depth])`
 fn parse_count<'sess>(
-    iter: &mut Cursor,
+    iter: &mut CursorRef<'_>,
     sess: &'sess ParseSess,
     span: Span,
 ) -> PResult<'sess, MetaVarExpr> {
@@ -97,7 +99,7 @@ fn parse_count<'sess>(
 
 /// Parses the depth used by index(depth) and length(depth).
 fn parse_depth<'sess>(
-    iter: &mut Cursor,
+    iter: &mut CursorRef<'_>,
     sess: &'sess ParseSess,
     span: Span,
 ) -> PResult<'sess, usize> {
@@ -110,7 +112,7 @@ fn parse_depth<'sess>(
             "meta-variable expression depth must be a literal"
         ));
     };
-    if let Ok(lit_kind) = LitKind::from_lit_token(lit)
+    if let Ok(lit_kind) = LitKind::from_lit_token(*lit)
         && let LitKind::Int(n_u128, LitIntType::Unsuffixed) = lit_kind
         && let Ok(n_usize) = usize::try_from(n_u128)
     {
@@ -124,7 +126,7 @@ fn parse_depth<'sess>(
 
 /// Parses an generic ident
 fn parse_ident<'sess>(
-    iter: &mut Cursor,
+    iter: &mut CursorRef<'_>,
     sess: &'sess ParseSess,
     span: Span,
 ) -> PResult<'sess, Ident> {
@@ -132,7 +134,7 @@ fn parse_ident<'sess>(
         if let Some((elem, false)) = token.ident() {
             return Ok(elem);
         }
-        let token_str = pprust::token_to_string(&token);
+        let token_str = pprust::token_to_string(token);
         let mut err = sess.span_diagnostic.struct_span_err(
             span,
             &format!("expected identifier, found `{}`", &token_str)
@@ -150,7 +152,7 @@ fn parse_ident<'sess>(
 
 /// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
 /// iterator is not modified and the result is `false`.
-fn try_eat_comma(iter: &mut Cursor) -> bool {
+fn try_eat_comma(iter: &mut CursorRef<'_>) -> bool {
     if let Some(TokenTree::Token(token::Token { kind: token::Comma, .. })) = iter.look_ahead(0) {
         let _ = iter.next();
         return true;