Rollup merge of #94189 - GuillaumeGomez:scalar-lower-hex, r=RalfJung
Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of https://github.com/rust-lang/rust/pull/94091. r? ````@RalfJung````
This commit is contained in:
commit
f639ba634b
4 changed files with 14 additions and 14 deletions
|
@ -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) =>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -153,7 +153,16 @@ impl<Tag: Provenance> fmt::Display for Scalar<Tag> {
|
|||
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<Tag: Provenance> fmt::LowerHex for Scalar<Tag> {
|
||||
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<Tag> {
|
|||
// 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<Tag: Provenance> fmt::Display for ScalarMaybeUninit<Tag> {
|
|||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue