Skip to content

Commit 5713677

Browse files
committed
Merge the string printing paths of ty::Const
1 parent a92d97e commit 5713677

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,17 +1566,21 @@ define_print_and_forward_display! {
15661566
(ConstValue::Scalar(Scalar::Bits { bits, ..}), ty::Char)
15671567
=> p!(write("{}", ::std::char::from_u32(bits as u32).unwrap())),
15681568
(_, ty::FnDef(did, _)) => p!(write("{}", cx.tcx().def_path_str(*did))),
1569-
(ConstValue::Slice(_, 0), ty::Ref(_, &ty::TyS { sty: ty::Str, .. }, _)) =>
1570-
p!(write("\"\"")),
15711569
(
1572-
ConstValue::Slice(Scalar::Ptr(ptr), len),
1570+
ConstValue::Slice(place, len),
15731571
ty::Ref(_, &ty::TyS { sty: ty::Str, .. }, _),
15741572
) => {
1575-
let alloc = cx.tcx().alloc_map.lock().unwrap_memory(ptr.alloc_id);
1576-
assert_eq!(len as usize as u64, len);
1577-
let slice =
1578-
&alloc.bytes[(ptr.offset.bytes() as usize)..][..(len as usize)];
1579-
let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");
1573+
let s = match (place, len) {
1574+
(_, 0) => "",
1575+
(Scalar::Ptr(ptr), len) => {
1576+
let alloc = cx.tcx().alloc_map.lock().unwrap_memory(ptr.alloc_id);
1577+
assert_eq!(len as usize as u64, len);
1578+
let slice =
1579+
&alloc.bytes[(ptr.offset.bytes() as usize)..][..(len as usize)];
1580+
::std::str::from_utf8(slice).expect("non utf8 str from miri")
1581+
},
1582+
_ => bug!("invalid slice: {:#?}", self),
1583+
};
15801584
p!(write("{:?}", s))
15811585
},
15821586
_ => p!(write("{:?} : ", self.val), print(self.ty)),

0 commit comments

Comments
 (0)