Skip to content

Commit 8cfc815

Browse files
committed
Remove Lit::from_included_bytes.
`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.
1 parent 8c6bf2b commit 8cfc815

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

compiler/rustc_ast/src/util/literal.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::ast::{self, Lit, LitKind};
44
use crate::token::{self, Token};
5-
use rustc_data_structures::sync::Lrc;
65
use rustc_lexer::unescape::{byte_from_char, unescape_byte, unescape_char, unescape_literal, Mode};
76
use rustc_span::symbol::{kw, sym, Symbol};
87
use rustc_span::Span;
@@ -215,13 +214,6 @@ impl Lit {
215214
Lit { token_lit: kind.to_token_lit(), kind, span }
216215
}
217216

218-
/// Recovers an AST literal from a string of bytes produced by `include_bytes!`.
219-
/// This requires ASCII-escaping the string, which can result in poor performance
220-
/// for very large strings of bytes.
221-
pub fn from_included_bytes(bytes: &Lrc<[u8]>, span: Span) -> Lit {
222-
Self::from_lit_kind(LitKind::ByteStr(bytes.clone()), span)
223-
}
224-
225217
/// Losslessly convert an AST literal into a token.
226218
pub fn to_token(&self) -> Token {
227219
let kind = match self.token_lit.kind {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ impl<'a> State<'a> {
328328
self.print_token_literal(token_lit, expr.span);
329329
}
330330
ast::ExprKind::IncludedBytes(ref bytes) => {
331-
let lit = ast::Lit::from_included_bytes(bytes, expr.span);
332-
self.print_literal(&lit)
331+
let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
332+
self.print_token_literal(lit, expr.span)
333333
}
334334
ast::ExprKind::Cast(ref expr, ref ty) => {
335335
let prec = AssocOp::As.precedence() as i8;

compiler/rustc_expand/src/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@ impl server::TokenStream for Rustc<'_, '_> {
526526
Ok(tokenstream::TokenStream::token_alone(token::Literal(*token_lit), expr.span))
527527
}
528528
ast::ExprKind::IncludedBytes(bytes) => {
529-
let lit = ast::Lit::from_included_bytes(bytes, expr.span);
529+
let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
530530
Ok(tokenstream::TokenStream::token_alone(
531-
token::TokenKind::Literal(lit.token_lit),
531+
token::TokenKind::Literal(lit),
532532
expr.span,
533533
))
534534
}

0 commit comments

Comments
 (0)