Skip to content

Commit 477a9b8

Browse files
committed
fix clippy (and MIR printing) handling of ConstValue::Indirect slices
1 parent b2d5d68 commit 477a9b8

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

clippy_utils/src/consts.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -671,19 +671,10 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
671671
ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))),
672672
_ => None,
673673
},
674-
mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() {
675-
ty::Ref(_, tam, _) => match tam.kind() {
676-
ty::Str => String::from_utf8(
677-
data.inner()
678-
.inspect_with_uninit_and_ptr_outside_interpreter(start..end)
679-
.to_owned(),
680-
)
681-
.ok()
682-
.map(Constant::Str),
683-
_ => None,
684-
},
685-
_ => None,
686-
},
674+
mir::ConstantKind::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => {
675+
let data = cv.try_get_slice_bytes_for_diagnostics(lcx.tcx)?;
676+
String::from_utf8(data.to_owned()).ok().map(Constant::Str)
677+
}
687678
mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => {
688679
let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory();
689680
match result.ty().kind() {

0 commit comments

Comments
 (0)