-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Don't show associated const value anymore #53409
Conversation
This comment has been minimized.
This comment has been minimized.
Did you check what it looks like if the constant is documented? If I just hide the code block for the definition with current rustdoc, the spacing around the docs seems closer to the next item than the one it documents. |
I didn't but I can add a pass for it if you want. |
I just mentioned it because I noticed it was messing up the spacing with my small CSS extension. |
Tagging some people who i know use associated consts in their documentation: @sgrif @SergioBenitez EDIT: Also, @rust-lang/docs, since this is a "what do we show in docs" question. Overall i'm fine with this, since like @nox said, it can leak internal information. I'd hoped there could be a more elegant/complicated way to deal with it, but i guess this solves an immediate problem. |
I've just realised that constant definitions should be hidden too, not just for associated constants. https://docs.rs/khronos_api/2.2.0/khronos_api/constant.EGL_XML.html |
Right, for Though I feel that it might depend. Sometimes the value of a constant is useful and relevant info, not absurdly long, and not "leaking" internal implementation details. #44348 (comment) mentions opaque wrappers, so maybe the presence of private fields (or the absence of public fields, for structs) could be a heuristic that affects the default. And may it’s worth having an attribute like |
One can always click on the |
That was the whole point of adding |
It's worth linking this PR to #49259 as well. |
I generally like this change. This might imply, however, that the actual value of a constant is not part of the public interface, which would mean that changing the value of a |
@SergioBenitez: From my point of view, you're supposed to use a const, not its value. So changing its value shouldn't impact someone's code. But that should be considered, indeed. |
I would agree with the assessment that the value of a const is not necessarily part of its semver guarantee, only its existence and type. Knowing what the value is is sometimes useful information, but unless you're tracking down a bug or looking for some performance issue you probably don't need to know what it looks like on the inside. It feels like all the people who have commented here agree on that? In some form? @GuillaumeGomez While you're doing this, can you also do this for non-associated consts, like @nox mentioned? |
Yes, I'll do it soon. |
f0a890d
to
a00706a
Compare
Remove constant and static initialization from documentation as well. |
This comment has been minimized.
This comment has been minimized.
I am extremely 👍 on not showing the value, I felt it was noisy when that was added |
2490d39
to
71a8984
Compare
This comment has been minimized.
This comment has been minimized.
71a8984
to
8614179
Compare
It seems to me that in the presence of const generics; the value of an associated const is absolutely part of the interface and can cause compilation errors. I'm quite skeptical about not showing associated consts long term therefore. |
What you say is already true without const generics and you can click on the source link to see the definition of the constant.
|
As @nox says, this is the case even today: trait Foo {
const BAR: usize;
}
struct Baz;
impl Foo for Baz {
const BAR: usize = 3; // Change this to 4 and we have a compilation error.
}
fn main() {
let arr: [u8; <Baz as Foo>::BAR] = [1, 2, 3];
} The more of (const) dependent types Rust gets, the more this becomes a problem. |
My point was that saying const generics are a reason to not do that is moot. The compile error you speak of only happens if you used the constant sometimes and its literal value some other times. That doesn’t happen if you use the constant exhaustively as one should.
Exposing the value currently means that we are leaking internal details and generating too much cruft in the rustdoc output.
…--
Anthony Ramine
Le 27 août 2018 à 19:08, Mazdak Farrokhzad ***@***.***> a écrit :
@QuietMisdreavus
I'm skeptical that changing the value of a const without changing its type will affect whether something compiles.
As @nox says, this is the case even today:
trait Foo {
const BAR: usize;
}
struct Baz;
impl Foo for Baz {
const BAR: usize = 3; // Change this to 4 and we have a compilation error.
}
fn main() {
let arr: [u8; <Baz as Foo>::BAR] = [1, 2, 3];
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Furthermore, even if we don’t hide constant definitions, your case still happen if you replace the constant BAR by a nullary const function that returns 3, yet I don’t think anyone would argue that rustdoc should show definitions of const functions.
|
Fair enough. |
If the value is informative for the user, it can always be repeated in the docstring. See e.g. |
Ping from triage @QuietMisdreavus / @GuillaumeGomez: What is the status of this PR? |
It seems to be ok. Not sure if the debate is over or not... |
Something to note for the people wanting a more-robust means of printing associated constants: Since @GuillaumeGomez didn't make this close the linked issue, i can only assume he has some plan up his sleeve? It can be extended later, but the current form of associated consts is unwieldy and awkward. If the concerns of @Centril, @SimonSapin, and/or whoever else was in this thread have been resolved, r=me. Side note: Is the |
@GuillaumeGomez my concerns are resolved. :) |
@QuietMisdreavus It's still in use apparently. And @Centril seems to be happy with changes. I'll let you r+ though. :p |
Ping from triage @QuietMisdreavus: It looks like this PR requires a final review from you. |
Welp, with no further comment, let's get this merged. @bors r+ |
📌 Commit 8614179 has been approved by |
…Misdreavus Don't show associated const value anymore Part of #44348. Before: <img width="1440" alt="screen shot 2018-08-16 at 00 48 30" src="https://user-images.githubusercontent.com/3050060/44177414-20ef1480-a0ee-11e8-80d4-7caf082cf0de.png"> After: <img width="1440" alt="screen shot 2018-08-16 at 00 48 23" src="https://user-images.githubusercontent.com/3050060/44177417-251b3200-a0ee-11e8-956a-4229275e3342.png"> cc @nox r? @QuietMisdreavus
☀️ Test successful - status-appveyor, status-travis |
The old test was supposed to check for proper html escaping when showing the contents of constants. This was changed as part of rust-lang#53409. The revised test asserts that the contents of the constant is not shown as part of the generated documentation.
Part of #44348.
Before:
After:
cc @nox
r? @QuietMisdreavus