Uh oh!
There was an error while loading. Please reload this page.
Show the actual value of constant values in the documentation - #66221
Conversation
rust-highfive
commented
Nov 8, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
GuillaumeGomez
commented
Nov 11, 2019
I'm not sure we want this... Why not keeping the original value and putting it into a link to its definition instead? |
ohadravid
commented
Nov 11, 2019
The motivating example here is I saw the tweet and it also happened to me multiple times so I figured I might as well fix it 🙂 Prior art: |
bors
commented
Nov 14, 2019
☔ The latest upstream changes (presumably #66233) made this pull request unmergeable. Please resolve the merge conflicts. |
216cfc6 to
b14632fCompareollie27
commented
Nov 22, 2019
ohadravid
commented
Nov 24, 2019
So in #53409 the problem seems to be over-detail when displaying a module, and this view it's not changed by this PR at all. For #42759, it's at least somewhat of an improvement because for non-scalar values we will mirror the source. However clearly the author of the issue wanted to see a value for the constant, so not showing anything is kind of a funny fix. #32735 is an ugly corner case, but I'll argue that there are more "should show the value of" than "should hide the value of" |
GuillaumeGomez
commented
Nov 25, 2019
I still have issue with this PR: in case it is a mathematical value like PI, why would I want the full number and not the constant PI? const stuff:f64 = math::PI;const stuff:f64 = 3.1415;I strongly prefer the first case. Even more considering that if you really want to see the full number, you can just click on the value... |
ohadravid
commented
Nov 26, 2019
What if we showed it like this (approximated html): Where the value part is only added for scalars? While remaining authentic to the original source code, it'll also solve the problem for |
GuillaumeGomez
commented
Nov 27, 2019
Providing the "complete" value as a comment would be fine for me. For example: |
ed5ef16 to
7b9ef3fCompareohadravid
commented
Nov 28, 2019
@GuillaumeGomez what do you think about this? It's a little noisy for some values (like |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
7b9ef3f to
d2d4429CompareGuillaumeGomez
commented
Nov 28, 2019
In the first case, since this is already a value, there is no need to add the comment. Can you not provide it in case this is "direct" value? (no idea how to express correctly what I have in mind, I hope people will understand XD) |
6a89be2 to
5062d47Compareohadravid
commented
Nov 29, 2019
I changed the code to not show the computed value for consts which are literals (or I implemented a version (diff) which adds the |
5062d47 to
de2ff01Comparerust-highfive
commented
Nov 29, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
de2ff01 to
4200924CompareGuillaumeGomez
commented
Nov 29, 2019
Instead of using HIR to check, can't you compare both displays and if they're the same, not print the comment one? |
ohadravid
commented
Nov 29, 2019
This is what the current code does, but it doesn't catch everything (like |
GuillaumeGomez
commented
Nov 29, 2019
Well I guess you can limit the display to nth first characters or something along the line? But yes, I think we're close to the end. Thanks so much for working on this! |
ohadravid
commented
Dec 4, 2019
@GuillaumeGomez I added splitting for big numbers! Let me know what you think. |
GuillaumeGomez
commented
Dec 8, 2019
@ohadravid Do you have screenshots by any chance? :) |
bors
commented
Dec 9, 2019
☔ The latest upstream changes (presumably #66984) made this pull request unmergeable. Please resolve the merge conflicts. |
ohadravid
commented
Dec 9, 2019
8f2fd28 to
7a10e20Comparebors
commented
Dec 11, 2019
☔ The latest upstream changes (presumably #67202) made this pull request unmergeable. Please resolve the merge conflicts. |
GuillaumeGomez
commented
Dec 11, 2019
Nice! Well then, unless @ollie27 wants something else to be updated, you can r=me once you have rebased. |
7a10e20 to
ea7b622Comparebors
commented
Dec 23, 2019
☔ The latest upstream changes (presumably #67540) made this pull request unmergeable. Please resolve the merge conflicts. |
ea7b622 to
53ff21eComparerust-highfive
commented
Dec 23, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
53ff21e to
e398f59Comparerust-highfive
commented
Dec 23, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
e398f59 to
531622aCompare531622a to
811bdeeCompareohadravid
commented
Dec 24, 2019
ping @ollie27? 🙏 |
Dylan-DPC-zz
commented
Dec 24, 2019
@bors r+ rollup |
bors
commented
Dec 24, 2019
📌 Commit 811bdee has been approved by |
bors
commented
Dec 24, 2019
🌲 The tree is currently closed for pull requests below priority 100, this pull request will be tested once the tree is reopened |
bors
commented
Dec 24, 2019
Show the actual value of constant values in the documentation Fixes#66099, making rustdoc show evaluated constant scalar values.  where `main.rs` is ``` pub const VAL3: i32 = i32::max_value(); pub const VAL4: i32 = i32::max_value() - 1; ``` As a fallback, when a constant value is not evaluated (either because of an error or because it isn't a scalar), the original expression is used for consistency. I mimicked the way min/max values of integers are [`pretty_print`ed](https://github.com/rust-lang/rust/blob/master/src/librustc/ty/print/pretty.rs#L900), to show both the value a the "hint". While a little goofy for `std`, in user crates I think it's actually rather helpful.
bors
commented
Dec 24, 2019
☀️ Test successful - checks-azure |


Fixes#66099, making rustdoc show evaluated constant scalar values.
where
main.rsisAs a fallback, when a constant value is not evaluated (either because of an error or because it isn't a scalar), the original expression is used for consistency.
I mimicked the way min/max values of integers are
pretty_printed, to show both the value a the "hint". While a little goofy forstd, in user crates I think it's actually rather helpful.