Skip to content

Commit c5ce3e1

Browse files
Don't render Const computed values in hexadecimal for Display
1 parent 6421a49 commit c5ce3e1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ impl<'tcx, Tag: Provenance> Scalar<Tag> {
456456
// Going through `u64` to check size and truncation.
457457
Ok(Double::from_bits(self.to_u64()?.into()))
458458
}
459+
460+
// FIXME: Replace current `impl Display for Scalar` with `impl LowerHex`.
461+
pub fn rustdoc_display(&self) -> String {
462+
if let Scalar::Int(int) = self { int.to_string() } else { self.to_string() }
463+
}
459464
}
460465

461466
#[derive(Clone, Copy, Eq, PartialEq, TyEncodable, TyDecodable, HashStable, Hash)]

compiler/rustc_middle/src/ty/consts/int.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,10 @@ impl fmt::UpperHex for ScalarInt {
374374
write!(f, "{:01$X}", { self.data }, self.size as usize * 2)
375375
}
376376
}
377+
378+
impl fmt::Display for ScalarInt {
379+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
380+
self.check_data();
381+
write!(f, "{}", { self.data })
382+
}
383+
}

src/librustdoc/clean/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: &ty::Const<'_>) ->
302302
// For all other types, fallback to the original `pretty_print_const`.
303303
match (ct.val, ct.ty.kind()) {
304304
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Uint(ui)) => {
305-
format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str())
305+
format!(
306+
"{}{}",
307+
format_integer_with_underscore_sep(&int.rustdoc_display()),
308+
ui.name_str()
309+
)
306310
}
307311
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Int(i)) => {
308312
let ty = tcx.lift(ct.ty).unwrap();

0 commit comments

Comments
 (0)