Introduce ExprKind::IncludedBytes
This commit is contained in:
parent
b7b7f2716e
commit
b2da155a9a
19 changed files with 78 additions and 15 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
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;
|
||||
|
@ -231,6 +232,13 @@ impl 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue