-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix rustdoc const computed value #94091
Fix rustdoc const computed value #94091
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
// all the Miri types. | ||
impl<Tag: Provenance> fmt::Display for Pointer<Tag> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
Provenance::fmt(self, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of duplicating the code, please make one of Display
and Debug
dispatch to the other (not sure which way makes more sense, but with the existing comment it probably makes most sense to have Debug
call Display
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep both even if duplicated. It allows to have two different formatting depending on what you need like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we won't need two different ones, so forwarding makes it easier for future readers to see that they are the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Now I have a question: do you to have instead for Debug
:
write!(f, "{}", self)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have assumed fmt::Display::fmt(self, f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows to have two different formatting depending on what you need like that.
The issue is that it is entirely unclear which style is used where -- both debug and display end up being user-visible in various situations, and when changing the code it becomes extremely hard to predict which one will change which output. IOW we can't actually meaningfully make them different, currently, since the consequences are so unclear. That is why I entirely removed many of the Display
implementations for Miri types -- then at least there is no ambiguity over which kind of formatting is used.
This PR adds back some of those instances which I removed; if that cannot be avoided I won't block it but then we can at least consistently use the pattern of forwarding one to the other.
9702022
to
edab15b
Compare
This comment has been minimized.
This comment has been minimized.
@@ -152,8 +152,8 @@ impl<Tag: Provenance> fmt::Debug for Scalar<Tag> { | |||
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes the ui test fallout. Please make sure the code that prints ui tests uses the debug formatting then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@oli-obk: I'm actually wondering: is there any reason why we display in hex instead of decimal? The error messages look simpler to me this way. |
For large values, hex becomes more readable - in particular things close to INT_MAX. Also we use leading zeroes to indicate the size of the value we talk about -- 0x03 and 0x0003 are not the same thing. These are data representations we talk about, which means they are usually very byte-driven, which makes hex often the better representation. |
Ok. Using |
These scalars are not necessarily integers. We're printing them as hex, because that's essentially the memory representation. Anything the layout algorithm decides is a Also: We can certainly open a discussion on the diagnostics of CTFE failures, but not as a drive by change of something unrelated. |
Not really -- it's still pretty hard to recognize 0xffff_ffff when written in decimal, even if the thousands are separated via |
edab15b
to
277a678
Compare
It was a nightmare to get through all the changes and find out what was broken so I took the easy way out and simply made a smaller change in rustdoc and in the |
This comment has been minimized.
This comment has been minimized.
Which broke things in a completely different way... |
277a678
to
04c319a
Compare
Seems like my fix worked! \o/ |
Hm, but that leaves us with 3 ways to print a Scalar, and it also means rustdoc has to break the I think |
Considering the complexity of it, I'd much rather do it in another PR. |
Well, if Rust had private enums then this PR wouldn't even work... quoting from the
|
True but I don't really care about the value inside, just want to display it. I can use |
Then you won't be able to print pointer values. Pointers and integers are very different beasts and neither subsumes the other. That's why we have the display impls in that module... I don't think changing the current |
Sounds like a plan! |
04c319a
to
296adba
Compare
Updated! I added a FIXME comment too as you asked. Once this is merged, I think I'll give it a try. |
@bors r+ |
📌 Commit 296adba has been approved by |
@bors rollup |
…ed-value, r=oli-obk Fix rustdoc const computed value Fixes rust-lang#85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? `@oli-obk`
…ed-value, r=oli-obk Fix rustdoc const computed value Fixes rust-lang#85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? ``@oli-obk``
…ed-value, r=oli-obk Fix rustdoc const computed value Fixes rust-lang#85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? ```@oli-obk```
…askrgr Rollup of 14 pull requests Successful merges: - rust-lang#93580 (Stabilize pin_static_ref.) - rust-lang#93639 (Release notes for 1.59) - rust-lang#93686 (core: Implement ASCII trim functions on byte slices) - rust-lang#94002 (rustdoc: Avoid duplicating macros in sidebar) - rust-lang#94019 (removing architecture requirements for RustyHermit) - rust-lang#94023 (adapt static-nobundle test to use llvm-nm) - rust-lang#94091 (Fix rustdoc const computed value) - rust-lang#94093 (Fix pretty printing of enums without variants) - rust-lang#94097 (Add module-level docs for `rustc_middle::query`) - rust-lang#94112 (Optimize char_try_from_u32) - rust-lang#94113 (document rustc_middle::mir::Field) - rust-lang#94122 (Fix miniz_oxide types showing up in std docs) - rust-lang#94142 (rustc_typeck: adopt let else in more places) - rust-lang#94146 (Adopt let else in more places) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…RalfJung Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of rust-lang#94091. r? `@RalfJung`
…RalfJung Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of rust-lang#94091. r? ``@RalfJung``
…RalfJung Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of rust-lang#94091. r? ```@RalfJung```
…RalfJung Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of rust-lang#94091. r? ````@RalfJung````
Fixes #85088.
It looks like this now (instead of hexadecimal):
r? @oli-obk