Skip to content

Commit 2b5ce93

Browse files
committed
Better print ScalarPair when it is slice
Signed-off-by: xizheyin <[email protected]>
1 parent cb6785f commit 2b5ce93

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,23 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
213213
write!(f, "{:x}: {}", s, self.layout.ty)
214214
}
215215
Immediate::ScalarPair(a, b) => {
216-
// FIXME(oli-obk): at least print tuples and slices nicely
216+
// Try to print slices nicely first
217+
// It's *only* printed for internal debugging
218+
if let Some(ty) = tcx.lift(self.layout.ty)
219+
&& let ty::Slice(element_ty) = ty.kind()
220+
{
221+
// For slices, the first scalar is the pointer, second is the length
222+
let ptr_str = FmtPrinter::print_string(tcx, Namespace::ValueNS, |cx| {
223+
p(cx, a, Ty::new_ptr(tcx, *element_ty, ty::Mutability::Not))
224+
})?;
225+
let len_str = FmtPrinter::print_string(tcx, Namespace::ValueNS, |cx| {
226+
p(cx, b, tcx.types.usize)
227+
})?;
228+
229+
write!(f, "&[{}; {}]: {}", ptr_str, len_str, ty)?;
230+
return Ok(());
231+
}
232+
// Fallback to the original format if we can't pretty print
217233
write!(f, "({:x}, {:x}): {}", a, b, self.layout.ty)
218234
}
219235
Immediate::Uninit => {

0 commit comments

Comments
 (0)