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

Add a default flag for enum documentation #115575

Closed
wants to merge 1 commit into from
Closed

Conversation

omid
Copy link

@omid omid commented Sep 5, 2023

fixes #115438

Disclaimer: It's my first PR, I don't know the regulation here yet 🙏🏼
I'm not sure if there are some styling standards, who's responsible for that and also I couldn't find tests for enum docs, for example if an enum is non_exhaustive or not.
I also don't know how I can test the code I've written, in general!

@rustbot
Copy link
Collaborator

rustbot commented Sep 5, 2023

Failed to set assignee to fmease: invalid assignee

Note: Only org members, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot
Copy link
Collaborator

rustbot commented Sep 5, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fmease (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Sep 5, 2023
@fmease
Copy link
Member

fmease commented Sep 5, 2023

r? @fmease

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I have a couple of suggestions regarding the implementation.
However, I'm not sure if we want to pursue this feature at all as I've noted in the relevant issue.
Let's first hear what the others have to say over there in reply to my comment.

src/librustdoc/html/render/print_item.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/print_item.rs Outdated Show resolved Hide resolved
@fmease
Copy link
Member

fmease commented Sep 6, 2023

I also don't know how I can test the code I've written, in general!

If you mean you don't know how to manually test (i.e., run and check) the code, I can only recommend https://rustc-dev-guide.rust-lang.org (search for rustdoc and rustup toolchain link), you can then run rustdoc +stage2 input.rs (and similar).

If you would like to know how to write a test, check out the tests in tests/rustdoc/ as well as src/tools/htmldocck.py for a list of the syntax. I don't think we have a test file for attributes We do have tests/rustdoc/attributes.rs.

@fmease
Copy link
Member

fmease commented Sep 6, 2023

@rustbot label -S-waiting-on-review S-waiting-on-team

@rustbot rustbot added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2023
@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Sep 7, 2023

I'll add this to the rustdoc team meeting list to be discussed in next meeting.

EDIT: Mostly for the UI part.

@bors
Copy link
Contributor

bors commented Sep 7, 2023

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

@fmease fmease added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Oct 6, 2023
@fmease
Copy link
Member

fmease commented Oct 16, 2023

Sorry for the delay. The rustdoc team seems to be in favor of showing this information (Zulip). They're not in favor of showing #[default] in the source code snippet (.item-decl) but only at the variants' docs in the form of a “chip” (I assume they mean a colored box similar to the ones shown on unstable and deprecated items).

Could you rebase your PR, address my old review comments and adapt to the suggested format?

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 16, 2023
@omid
Copy link
Author

omid commented Oct 17, 2023

@fmease to be on the same page... you mean something like the 👎🏼 section in the picture below:
image

But in the "Variants" area, like here:
image

@fmease
Copy link
Member

fmease commented Oct 17, 2023

Yes, exactly! Just to make sure: @Manishearth, is this ^ what you meant by “chip” on Zulip?

@omid
Copy link
Author

omid commented Oct 17, 2023

Thanks, in this case, let's agree on the emoji and text also.

So far:
1.
image
2.
image
3.
image

or something else?
I think the 3rd one looks better.

@GuillaumeGomez
Copy link
Member

I vote for 2 or 3.

@fmease
Copy link
Member

fmease commented Oct 17, 2023

Personally speaking I like option 3 the most :)

@Manishearth
Copy link
Member

3 > 1 > 2 for me, strong preference for 3

@omid omid marked this pull request as draft October 17, 2023 21:07
@omid omid marked this pull request as ready for review October 18, 2023 08:36
@omid

This comment was marked as outdated.

@notriddle
Copy link
Contributor

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Oct 29, 2023

Team member @notriddle has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 29, 2023
@camelid
Copy link
Member

camelid commented Dec 4, 2023

@rfcbot concern usefulness

I think this is an interesting feature, but I'm concerned about its usefulness and its possibility of causing confusion. The chip only appears on variants that are marked with the relatively new #[default] attribute, and the attribute only supports fieldless variants. So it only appears in a small subset of cases. But then, if the author used a manual Default impl (either because they wrote the code before #[default], or because the default needs to have fields), it won't have a "Default" chip. IMO this could be confusing to (especially new) users, who see "Default" chips on some variants but not others, even though the others also have Default impls. They may not realize that enums that don't have the chip on them can (and often do) still have defaults on them.

@GuillaumeGomez
Copy link
Member

Also an important note about getting the default enum variant from the Default trait impl: if the returned value depends on a static variable or anything that could return different values at different point of the program, it'd be impossible for rustdoc to get the correct value.

And finally, the #[default] currently seem to be able to be used on unit variants, limiting its usefulness even further.

@notriddle
Copy link
Contributor

I used to weakly support this change, but after hearing camelid's argument, changed my mind and retracted my checkmark.

We don't need built-in support for stuff like this.

  • In APIs that really do benefit from pointing out which variant the default is, the doc author can use their words and say /// This variant is returned by Default::default()`.
  • Implementing Default is often bad API design. It should only be used if it's going to be obvious at the call site what it's going to return. Otherwise, the API should be designed with more specifically named functions.
    • We should use sugar like this to reward good design. Paradoxically, the better-designed the API is, the less useful the default badge would be. This feature rewards bad API design.

@fmease fmease added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 10, 2023
@fmease
Copy link
Member

fmease commented Dec 10, 2023

It seems like the majority of team members has changed their opinion towards closing this PR. So far, nobody has put forward any arguments against the concern (which agrees with my initial sentiment). fcp-close then?

@notriddle
Copy link
Contributor

@rfcbot fcp cancel

@rfcbot fcp close

@rfcbot
Copy link

rfcbot commented Dec 10, 2023

@notriddle proposal cancelled.

@rfcbot rfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Dec 10, 2023
@rfcbot
Copy link

rfcbot commented Dec 10, 2023

Team member @notriddle has proposed to close this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. labels Dec 10, 2023
@fmease fmease added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Dec 14, 2023
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jan 21, 2024
@rfcbot
Copy link

rfcbot commented Jan 21, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jan 21, 2024
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jan 31, 2024
@rfcbot
Copy link

rfcbot commented Jan 31, 2024

The final comment period, with a disposition to close, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@GuillaumeGomez
Copy link
Member

Closing then. Thanks again for bringing this to our attention @omid !

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-close This PR / issue is in PFCP or FCP with a disposition to close it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. 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.

Highlight default enum variant in rustdoc output
10 participants