]> git.lizzy.rs Git - rust.git/commitdiff
Remove `Lit::from_included_bytes`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Wed, 23 Nov 2022 06:00:37 +0000 (17:00 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 28 Nov 2022 04:17:45 +0000 (15:17 +1100)
`Lit::from_included_bytes` calls `Lit::from_lit_kind`, but the two call
sites only need the resulting `token::Lit`, not the full `ast::Lit`.

This commit changes those call sites to use `LitKind::to_token_lit`,
which means `from_included_bytes` can be removed.

compiler/rustc_ast/src/util/literal.rs
compiler/rustc_ast_pretty/src/pprust/state/expr.rs
compiler/rustc_expand/src/proc_macro_server.rs

index db2ac9626afd58e357f284103db6f07f893b42a8..8eec869fbe5f05257979318f59b804318a3418a0 100644 (file)
@@ -2,7 +2,6 @@
 
 use crate::ast::{self, Lit, LitKind};
 use crate::token::{self, Token};
-use rustc_data_structures::sync::Lrc;
 use rustc_lexer::unescape::{byte_from_char, unescape_byte, unescape_char, unescape_literal, Mode};
 use rustc_span::symbol::{kw, sym, Symbol};
 use rustc_span::Span;
@@ -215,13 +214,6 @@ pub fn from_lit_kind(kind: LitKind, span: Span) -> Lit {
         Lit { token_lit: kind.to_token_lit(), kind, span }
     }
 
-    /// Recovers an AST literal from a string of bytes produced by `include_bytes!`.
-    /// This requires ASCII-escaping the string, which can result in poor performance
-    /// for very large strings of bytes.
-    pub fn from_included_bytes(bytes: &Lrc<[u8]>, span: Span) -> Lit {
-        Self::from_lit_kind(LitKind::ByteStr(bytes.clone()), span)
-    }
-
     /// Losslessly convert an AST literal into a token.
     pub fn to_token(&self) -> Token {
         let kind = match self.token_lit.kind {
index 949d98f96ab6a8166802f4b76ba922c1e84ec2c4..f4d77549eff4cc77a3a374cd9267b5678b741ef9 100644 (file)
@@ -328,8 +328,8 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
                 self.print_token_literal(token_lit, expr.span);
             }
             ast::ExprKind::IncludedBytes(ref bytes) => {
-                let lit = ast::Lit::from_included_bytes(bytes, expr.span);
-                self.print_literal(&lit)
+                let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
+                self.print_token_literal(lit, expr.span)
             }
             ast::ExprKind::Cast(ref expr, ref ty) => {
                 let prec = AssocOp::As.precedence() as i8;
index 2e832deeecda0ed0645bbde1d4a5ec6da2ccf808..b69556c0e7cc208da465d02b01f7e3387b984549 100644 (file)
@@ -526,9 +526,9 @@ fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStrea
                 Ok(tokenstream::TokenStream::token_alone(token::Literal(*token_lit), expr.span))
             }
             ast::ExprKind::IncludedBytes(bytes) => {
-                let lit = ast::Lit::from_included_bytes(bytes, expr.span);
+                let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
                 Ok(tokenstream::TokenStream::token_alone(
-                    token::TokenKind::Literal(lit.token_lit),
+                    token::TokenKind::Literal(lit),
                     expr.span,
                 ))
             }