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

rustdoc: Render private fields in tuple struct as /* private fields */ #110552

Closed

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 19, 2023

I've gotten some feedback that the current rustdoc rendering of...

struct HasPrivateFields(_);

...is confusing, and I agree with that feedback, especially compared to the field struct case:

struct HasPrivateFields { /* private fields */ }

So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the /* private fields */ comment. We can't always render it like that, for example when there's a mix of private and public fields.


Not sure if this is a worthwhile change, so opening it up for discussion :)

@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2023

r? @jsha

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 19, 2023
@jsha
Copy link
Contributor

jsha commented Apr 21, 2023

This looks like a good idea to me. For the test updates: for the tests that aren't intentionally testing the rendering of private fields (e.g. tests/rustdoc/const-generics/const-generic-defaults.rs), we should update the test expectations so they don't make a statement one way or the other about private fields. Since the test expectation is based on substring matching I think it should suffice to remove everything after the (. Alternately we could make the fields in question pub but it seems nicer to avoid saying anything about the fields when the rendering of the fields isn't an issue.

@GuillaumeGomez
Copy link
Member

Looks good to me as well. Can you add one test which specifically check the following cases:

  • First field is public, second is private.
  • First field is private, second is public.
  • First private, second public, third private.
  • First public, second private, third public.
  • All fields private:
    • One struct with only one field
    • One struct with two fields

please? (I think they cover all possible cases I could think of)

Once done, I'll start an FCP to get the approval from the rest of the team since it's a user facing change.

@bors
Copy link
Contributor

bors commented Jun 23, 2023

☔ The latest upstream changes (presumably #112957) made this pull request unmergeable. Please resolve the merge conflicts.

@jsha jsha added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2023
@jsha
Copy link
Contributor

jsha commented Aug 16, 2023

Just a friendly bump on this. @GuillaumeGomez requested above some additional test cases. And there are a merge conflicts. I think this is a good improvement and it would be nice to get it merged.

@compiler-errors
Copy link
Member Author

don't really have time to update this pr -- would be a good beginner issue tho.

@GuillaumeGomez
Copy link
Member

I'll take over as this is a bug fix.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 7, 2023
…e-struct, r=notriddle

rustdoc: Render private fields in tuple struct as `/* private fields */`

Reopening of rust-lang#110552. All that was missing was a test for the different cases so I added it into the second commit.

Description from the original PR:

> I've gotten some feedback that the current rustdoc rendering of...
>
> ```
> struct HasPrivateFields(_);
> ```
>
> ...is confusing, and I agree with that feedback, especially compared to the field struct case:
>
> ```
> struct HasPrivateFields { /* private fields */ }
> ```
>
> So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields.

cc `@jsha`
r? `@notriddle`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 7, 2023
…e-struct, r=notriddle

rustdoc: Render private fields in tuple struct as `/* private fields */`

Reopening of rust-lang#110552. All that was missing was a test for the different cases so I added it into the second commit.

Description from the original PR:

> I've gotten some feedback that the current rustdoc rendering of...
>
> ```
> struct HasPrivateFields(_);
> ```
>
> ...is confusing, and I agree with that feedback, especially compared to the field struct case:
>
> ```
> struct HasPrivateFields { /* private fields */ }
> ```
>
> So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields.

cc ``@jsha``
r? ``@notriddle``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 7, 2023
…e-struct, r=notriddle

rustdoc: Render private fields in tuple struct as `/* private fields */`

Reopening of rust-lang#110552. All that was missing was a test for the different cases so I added it into the second commit.

Description from the original PR:

> I've gotten some feedback that the current rustdoc rendering of...
>
> ```
> struct HasPrivateFields(_);
> ```
>
> ...is confusing, and I agree with that feedback, especially compared to the field struct case:
>
> ```
> struct HasPrivateFields { /* private fields */ }
> ```
>
> So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields.

cc ```@jsha```
r? ```@notriddle```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 8, 2023
…e-struct, r=notriddle

rustdoc: Render private fields in tuple struct as `/* private fields */`

Reopening of rust-lang#110552. All that was missing was a test for the different cases so I added it into the second commit.

Description from the original PR:

> I've gotten some feedback that the current rustdoc rendering of...
>
> ```
> struct HasPrivateFields(_);
> ```
>
> ...is confusing, and I agree with that feedback, especially compared to the field struct case:
>
> ```
> struct HasPrivateFields { /* private fields */ }
> ```
>
> So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields.

cc ````@jsha````
r? ````@notriddle````
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2023
Rollup merge of rust-lang#115604 - GuillaumeGomez:private-fields-tuple-struct, r=notriddle

rustdoc: Render private fields in tuple struct as `/* private fields */`

Reopening of rust-lang#110552. All that was missing was a test for the different cases so I added it into the second commit.

Description from the original PR:

> I've gotten some feedback that the current rustdoc rendering of...
>
> ```
> struct HasPrivateFields(_);
> ```
>
> ...is confusing, and I agree with that feedback, especially compared to the field struct case:
>
> ```
> struct HasPrivateFields { /* private fields */ }
> ```
>
> So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields.

cc ````@jsha````
r? ````@notriddle````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants