about summary refs log tree commit diff
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
commit477a9b88bf31168e747a463b4942a8d64ae5917d (patch)
treeaea70a96cd2a47f00a8a66221f660e56a9b6cd2e
parentb2d5d68c58a745c80bc0187dba8c85e1519faabc (diff)
downloadrust-477a9b88bf31168e747a463b4942a8d64ae5917d.tar.gz
rust-477a9b88bf31168e747a463b4942a8d64ae5917d.zip
fix clippy (and MIR printing) handling of ConstValue::Indirect slices
-rw-r--r--clippy_utils/src/consts.rs17
1 files changed, 4 insertions, 13 deletions
diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs
index 61b944667a4..fcb90c63a6f 100644
--- a/clippy_utils/src/consts.rs
+++ b/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() {