about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-09-12 14:44:38 +0200
committerRalf Jung <post@ralfj.de>2023-09-14 11:56:55 +0200
commitb18c0a8c4e641d97406fc574d965a74ec4cda3d1 (patch)
treeb8e91810f85c76c6e8373694600e02e157b3252c /src/tools
parent0a6e263b9f57ffeda85404943475b22302429bfa (diff)
downloadrust-b18c0a8c4e641d97406fc574d965a74ec4cda3d1.tar.gz
rust-b18c0a8c4e641d97406fc574d965a74ec4cda3d1.zip
fix clippy (and MIR printing) handling of ConstValue::Indirect slices
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clippy/clippy_utils/src/consts.rs17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs
index 61b944667a4..fcb90c63a6f 100644
--- a/src/tools/clippy/clippy_utils/src/consts.rs
+++ b/src/tools/clippy/clippy_utils/src/consts.rs
@@ -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()))),
             _ => None,
         },
-        mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() {
-            ty::Ref(_, tam, _) => match tam.kind() {
-                ty::Str => String::from_utf8(
-                    data.inner()
-                        .inspect_with_uninit_and_ptr_outside_interpreter(start..end)
-                        .to_owned(),
-                )
-                .ok()
-                .map(Constant::Str),
-                _ => None,
-            },
-            _ => None,
-        },
+        mir::ConstantKind::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => {
+            let data = cv.try_get_slice_bytes_for_diagnostics(lcx.tcx)?;
+            String::from_utf8(data.to_owned()).ok().map(Constant::Str)
+        }
         mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => {
             let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory();
             match result.ty().kind() {