diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 051ae228e22..28305bbe81c 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -1121,11 +1121,13 @@ fn lower_literal_to_operand(&mut self, ty: Ty, l: &Literal) -> Result { } hir_def::hir::Literal::CString(b) => { let b = b.as_bytes(); + let bytes = b.iter().copied().chain(iter::once(0)).collect::>(); + let mut data = Vec::with_capacity(mem::size_of::() * 2); data.extend(0usize.to_le_bytes()); - data.extend(b.len().to_le_bytes()); + data.extend(bytes.len().to_le_bytes()); let mut mm = MemoryMap::default(); - mm.insert(0, b.iter().copied().chain(iter::once(0)).collect::>()); + mm.insert(0, bytes); return Ok(Operand::from_concrete_const(data, mm, ty)); } hir_def::hir::Literal::ByteString(b) => {