Remove extra indirection in LitKind::ByteStr

This commit is contained in:
Robin Schoonover 2020-09-16 19:41:22 -06:00
parent 4ccf5f731b
commit 5ab19676ed
4 changed files with 5 additions and 8 deletions

View File

@ -1606,7 +1606,7 @@ pub enum LitKind {
/// A string literal (`"foo"`).
Str(Symbol, StrStyle),
/// A byte string (`b"foo"`).
ByteStr(Lrc<Vec<u8>>),
ByteStr(Lrc<[u8]>),
/// A byte char (`b'f'`).
Byte(u8),
/// A character literal (`'a'`).

View File

@ -4,7 +4,6 @@ use crate::ast::{self, Lit, LitKind};
use crate::token::{self, Token};
use crate::tokenstream::TokenTree;
use rustc_data_structures::sync::Lrc;
use rustc_lexer::unescape::{unescape_byte, unescape_char};
use rustc_lexer::unescape::{unescape_byte_literal, unescape_literal, Mode};
use rustc_span::symbol::{kw, sym, Symbol};
@ -108,7 +107,7 @@ impl LitKind {
});
error?;
buf.shrink_to_fit();
LitKind::ByteStr(Lrc::new(buf))
LitKind::ByteStr(buf.into())
}
token::ByteStrRaw(_) => {
let s = symbol.as_str();
@ -128,7 +127,7 @@ impl LitKind {
symbol.to_string().into_bytes()
};
LitKind::ByteStr(Lrc::new(bytes))
LitKind::ByteStr(bytes.into())
}
token::Err => LitKind::Err(symbol),
})

View File

@ -13,8 +13,6 @@ use rustc_span::{self, Pos, Span};
use smallvec::SmallVec;
use std::rc::Rc;
use rustc_data_structures::sync::Lrc;
// These macros all relate to the file system; they either return
// the column/row/filename of the expression, or they include
// a given file into the current one.
@ -216,7 +214,7 @@ pub fn expand_include_bytes(
}
};
match cx.source_map().load_binary_file(&file) {
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))),
Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(bytes.into()))),
Err(e) => {
cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e));
DummyResult::any(sp)

View File

@ -31,7 +31,7 @@ crate fn lit_to_const<'tcx>(
(ast::LitKind::ByteStr(data), ty::Ref(_, inner_ty, _))
if matches!(inner_ty.kind(), ty::Slice(_)) =>
{
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
let allocation = Allocation::from_byte_aligned_bytes(data as &[u8]);
let allocation = tcx.intern_const_alloc(allocation);
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
}