about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-04-02 14:26:28 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-05-25 10:07:01 +0200
commit5713677862b716ed65f653ed065128c98e6fcbb6 (patch)
treed2a11c8388abb15cfbfbe1b738ade574b8d02282
parenta92d97ee70e84e3568eb28cf8e01d2ac6a67e12c (diff)
downloadrust-5713677862b716ed65f653ed065128c98e6fcbb6.tar.gz
rust-5713677862b716ed65f653ed065128c98e6fcbb6.zip
Merge the string printing paths of ty::Const
-rw-r--r--src/librustc/ty/print/pretty.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs
index 81f5c87184e..085a0edc986 100644
--- a/src/librustc/ty/print/pretty.rs
+++ b/src/librustc/ty/print/pretty.rs
@@ -1566,17 +1566,21 @@ define_print_and_forward_display! {
             (ConstValue::Scalar(Scalar::Bits { bits, ..}), ty::Char)
                 => p!(write("{}", ::std::char::from_u32(bits as u32).unwrap())),
             (_, ty::FnDef(did, _)) => p!(write("{}", cx.tcx().def_path_str(*did))),
-            (ConstValue::Slice(_, 0), ty::Ref(_, &ty::TyS { sty: ty::Str, .. }, _)) =>
-                p!(write("\"\"")),
             (
-                ConstValue::Slice(Scalar::Ptr(ptr), len),
+                ConstValue::Slice(place, len),
                 ty::Ref(_, &ty::TyS { sty: ty::Str, .. }, _),
             ) => {
-                let alloc = cx.tcx().alloc_map.lock().unwrap_memory(ptr.alloc_id);
-                assert_eq!(len as usize as u64, len);
-                let slice =
-                    &alloc.bytes[(ptr.offset.bytes() as usize)..][..(len as usize)];
-                let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");
+                let s = match (place, len) {
+                    (_, 0) => "",
+                    (Scalar::Ptr(ptr), len) => {
+                        let alloc = cx.tcx().alloc_map.lock().unwrap_memory(ptr.alloc_id);
+                        assert_eq!(len as usize as u64, len);
+                        let slice =
+                            &alloc.bytes[(ptr.offset.bytes() as usize)..][..(len as usize)];
+                        ::std::str::from_utf8(slice).expect("non utf8 str from miri")
+                    },
+                    _ => bug!("invalid slice: {:#?}", self),
+                };
                 p!(write("{:?}", s))
             },
             _ => p!(write("{:?} : ", self.val), print(self.ty)),