diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-02-17 17:58:38 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-02-19 14:00:36 +0100 |
| commit | c5ce3e1dbc86a9155e5bb81cbbb76c94647f0eb9 (patch) | |
| tree | 313348b0302c6542cdd1ec253684f4aafa6ab7d3 | |
| parent | 6421a499a50adbaa7b5d0234bdd4817d970f0933 (diff) | |
| download | rust-c5ce3e1dbc86a9155e5bb81cbbb76c94647f0eb9.tar.gz rust-c5ce3e1dbc86a9155e5bb81cbbb76c94647f0eb9.zip | |
Don't render Const computed values in hexadecimal for Display
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/value.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts/int.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/clean/utils.rs | 6 |
3 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index cc31d8c2c18..aa8730bf9cd 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -456,6 +456,11 @@ 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)] diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index de45e1bb851..10a9a16a4c7 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -374,3 +374,10 @@ impl fmt::UpperHex for ScalarInt { write!(f, "{:01$X}", { self.data }, self.size as usize * 2) } } + +impl fmt::Display for ScalarInt { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.check_data(); + write!(f, "{}", { self.data }) + } +} diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 3a83f4505a5..a68e325481e 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -302,7 +302,11 @@ fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: &ty::Const<'_>) -> // 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.to_string()), ui.name_str()) + format!( + "{}{}", + format_integer_with_underscore_sep(&int.rustdoc_display()), + ui.name_str() + ) } (ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Int(i)) => { let ty = tcx.lift(ct.ty).unwrap(); |
