Use debug impl in rendering const eval result

This commit is contained in:
hkalbasi 2023-07-08 01:07:38 +03:30
parent 4a444e768c
commit f0ba0dbe8a
4 changed files with 106 additions and 58 deletions

View file

@ -446,28 +446,6 @@ impl HirDisplay for Const {
}
}
pub struct HexifiedConst(pub Const);
impl HirDisplay for HexifiedConst {
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
let data = &self.0.data(Interner);
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
if let ConstValue::Concrete(c) = &data.value {
if let ConstScalar::Bytes(b, m) = &c.interned {
let value = u128::from_le_bytes(pad16(b, false));
if value >= 10 {
render_const_scalar(f, &b, m, &data.ty)?;
return write!(f, " ({:#X})", value);
}
}
}
}
}
self.0.hir_fmt(f)
}
}
fn render_const_scalar(
f: &mut HirFormatter<'_>,
b: &[u8],