Skip to content
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

Merged
merged 4 commits into from
Sep 12, 2018

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 15, 2018

Part of #44348.

Before:

screen shot 2018-08-16 at 00 48 30

After:

screen shot 2018-08-16 at 00 48 23

cc @nox

r? @QuietMisdreavus

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 15, 2018
@rust-highfive

This comment has been minimized.

@nox
Copy link
Contributor

nox commented Aug 17, 2018

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.

@GuillaumeGomez
Copy link
Member Author

I didn't but I can add a pass for it if you want.

@nox
Copy link
Contributor

nox commented Aug 18, 2018

I just mentioned it because I noticed it was messing up the spacing with my small CSS extension.

@GuillaumeGomez
Copy link
Member Author

Didn't see anything special despite the fact that the toggle wasn't added to associated const docs. I fixed it in my last commit. Now it looks like this:

screen shot 2018-08-18 at 18 10 37

screen shot 2018-08-18 at 18 10 57

@QuietMisdreavus
Copy link
Member

QuietMisdreavus commented Aug 21, 2018

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.

@nox
Copy link
Contributor

nox commented Aug 21, 2018

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

@SimonSapin
Copy link
Contributor

Right, for const items and static items it may make sense to not show the value, but that’s not related to whether the item is associated (in an impl) or module-level.

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 #[doc(value = "hidden")] and #[doc(value = "shown")].

@nox
Copy link
Contributor

nox commented Aug 22, 2018

One can always click on the [src] link to see the definition.

@GuillaumeGomez
Copy link
Member Author

One can always click on the [src] link to see the definition.

That was the whole point of adding [src] while removing the definition.

@QuietMisdreavus
Copy link
Member

It's worth linking this PR to #49259 as well.

@SergioBenitez
Copy link
Contributor

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 const is a semver-compatible change, all other things remaining the same. I believe that should be true, but it's something worth considering.

@GuillaumeGomez
Copy link
Member Author

@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.

@QuietMisdreavus
Copy link
Member

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?

@GuillaumeGomez
Copy link
Member Author

Yes, I'll do it soon.

@GuillaumeGomez
Copy link
Member Author

Remove constant and static initialization from documentation as well.

@rust-highfive

This comment has been minimized.

@sgrif
Copy link
Contributor

sgrif commented Aug 25, 2018

I am extremely 👍 on not showing the value, I felt it was noisy when that was added

@rust-highfive

This comment has been minimized.

@Centril
Copy link
Contributor

Centril commented Aug 27, 2018

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.

@nox
Copy link
Contributor

nox commented Aug 27, 2018 via email

@Centril
Copy link
Contributor

Centril commented Aug 27, 2018

@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];
}

The more of (const) dependent types Rust gets, the more this becomes a problem.

@nox
Copy link
Contributor

nox commented Aug 27, 2018 via email

@nox
Copy link
Contributor

nox commented Aug 27, 2018 via email

@Centril
Copy link
Contributor

Centril commented Aug 27, 2018

@nox

That doesn’t happen if you use the constant exhaustively as one should.

Fair enough.

@bluetech
Copy link

If the value is informative for the user, it can always be repeated in the docstring. See e.g. http::StatusCode.

@TimNN
Copy link
Contributor

TimNN commented Sep 4, 2018

Ping from triage @QuietMisdreavus / @GuillaumeGomez: What is the status of this PR?

@GuillaumeGomez
Copy link
Member Author

It seems to be ok. Not sure if the debate is over or not...

@QuietMisdreavus
Copy link
Member

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 prefix parameter of document_full/document_short/etc used any more? I seem to remember thinking that was its only use...

@Centril
Copy link
Contributor

Centril commented Sep 5, 2018

@GuillaumeGomez my concerns are resolved. :)

@GuillaumeGomez
Copy link
Member Author

@QuietMisdreavus It's still in use apparently. And @Centril seems to be happy with changes. I'll let you r+ though. :p

@TimNN
Copy link
Contributor

TimNN commented Sep 11, 2018

Ping from triage @QuietMisdreavus: It looks like this PR requires a final review from you.

@QuietMisdreavus
Copy link
Member

Welp, with no further comment, let's get this merged.

@bors r+

@bors
Copy link
Contributor

bors commented Sep 12, 2018

📌 Commit 8614179 has been approved by QuietMisdreavus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 12, 2018
@bors
Copy link
Contributor

bors commented Sep 12, 2018

⌛ Testing commit 8614179 with merge f2302da...

bors added a commit that referenced this pull request Sep 12, 2018
…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
@bors
Copy link
Contributor

bors commented Sep 12, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: QuietMisdreavus
Pushing f2302da to master...

@bors bors merged commit 8614179 into rust-lang:master Sep 12, 2018
@bors bors mentioned this pull request Sep 12, 2018
@GuillaumeGomez GuillaumeGomez deleted the associated-const-value branch September 13, 2018 09:21
Munksgaard added a commit to Munksgaard/rust that referenced this pull request Oct 4, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.