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;
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 {
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;
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,
))
}