fix clippy (and MIR printing) handling of ConstValue::Indirect slices

This commit is contained in:
Ralf Jung 2023-09-12 14:44:38 +02:00
parent b2d5d68c58
commit 477a9b88bf

View file

@ -671,19 +671,10 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))), ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))),
_ => None, _ => None,
}, },
mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() { mir::ConstantKind::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => {
ty::Ref(_, tam, _) => match tam.kind() { let data = cv.try_get_slice_bytes_for_diagnostics(lcx.tcx)?;
ty::Str => String::from_utf8( String::from_utf8(data.to_owned()).ok().map(Constant::Str)
data.inner() }
.inspect_with_uninit_and_ptr_outside_interpreter(start..end)
.to_owned(),
)
.ok()
.map(Constant::Str),
_ => None,
},
_ => None,
},
mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => { mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => {
let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory(); let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory();
match result.ty().kind() { match result.ty().kind() {