diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 5fec8963a2c45..19c6449078d5b 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -697,7 +697,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> this.ecx.read_discriminant(op), this.path, err_ub!(InvalidTag(val)) => - { "{}", val } expected { "a valid enum tag" }, + { "{:x}", val } expected { "a valid enum tag" }, err_ub!(InvalidUninitBytes(None)) => { "uninitialized bytes" } expected { "a valid enum tag" }, err_unsup!(ReadPointerAsBytes) => diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index e9a857d09124f..c5866924eda43 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -370,7 +370,7 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> { InvalidChar(c) => { write!(f, "interpreting an invalid 32-bit value as a char: 0x{:08x}", c) } - InvalidTag(val) => write!(f, "enum value has invalid tag: {}", val), + InvalidTag(val) => write!(f, "enum value has invalid tag: {:x}", val), InvalidFunctionPointer(p) => { write!(f, "using {:?} as function pointer but it does not point to a function", p) } diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index aa8730bf9cdde..abcf416109ba6 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -153,7 +153,16 @@ impl fmt::Display for Scalar { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Scalar::Ptr(ptr, _size) => write!(f, "pointer to {:?}", ptr), - Scalar::Int(int) => write!(f, "{:?}", int), + Scalar::Int(int) => write!(f, "{}", int), + } + } +} + +impl fmt::LowerHex for Scalar { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Scalar::Ptr(ptr, _size) => write!(f, "pointer to {:?}", ptr), + Scalar::Int(int) => write!(f, "0x{:x}", int), } } } @@ -456,11 +465,6 @@ impl<'tcx, Tag: Provenance> Scalar { // Going through `u64` to check size and truncation. Ok(Double::from_bits(self.to_u64()?.into())) } - - // FIXME: Replace current `impl Display for Scalar` with `impl LowerHex`. - pub fn rustdoc_display(&self) -> String { - if let Scalar::Int(int) = self { int.to_string() } else { self.to_string() } - } } #[derive(Clone, Copy, Eq, PartialEq, TyEncodable, TyDecodable, HashStable, Hash)] @@ -494,7 +498,7 @@ impl fmt::Display for ScalarMaybeUninit { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ScalarMaybeUninit::Uninit => write!(f, "uninitialized bytes"), - ScalarMaybeUninit::Scalar(s) => write!(f, "{}", s), + ScalarMaybeUninit::Scalar(s) => write!(f, "{:x}", s), } } } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index fe1992a5d7e31..1d312df1f7858 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -302,11 +302,7 @@ fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: ty::Const<'_>) -> S // For all other types, fallback to the original `pretty_print_const`. match (ct.val(), ct.ty().kind()) { (ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Uint(ui)) => { - format!( - "{}{}", - format_integer_with_underscore_sep(&int.rustdoc_display()), - ui.name_str() - ) + format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str()) } (ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Int(i)) => { let ty = tcx.lift(ct.ty()).unwrap();