support creating mutable allocations from byte slices
This commit is contained in:
parent
c3005e85da
commit
585141b219
8 changed files with 30 additions and 15 deletions
|
@ -25,14 +25,14 @@ crate fn lit_to_const<'tcx>(
|
|||
let lit = match (lit, &ty.kind()) {
|
||||
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
||||
let s = s.as_str();
|
||||
let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes());
|
||||
let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes());
|
||||
let allocation = tcx.intern_const_alloc(allocation);
|
||||
ConstValue::Slice { data: allocation, start: 0, end: s.len() }
|
||||
}
|
||||
(ast::LitKind::ByteStr(data), ty::Ref(_, inner_ty, _))
|
||||
if matches!(inner_ty.kind(), ty::Slice(_)) =>
|
||||
{
|
||||
let allocation = Allocation::from_byte_aligned_bytes(data as &[u8]);
|
||||
let allocation = Allocation::from_bytes_byte_aligned_immutable(data as &[u8]);
|
||||
let allocation = tcx.intern_const_alloc(allocation);
|
||||
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue