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: Tuple Fields of Variant section is superfluous and noisy if all fields are undocumented #90824

Closed
orlp opened this issue Nov 12, 2021 · 10 comments · Fixed by #91687
Closed
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@orlp
Copy link
Contributor

orlp commented Nov 12, 2021

I understand that if (at least one of) a tuple variant's fields is documented, we need a place to put that documentation. But if not this just adds superfluous noise. Especially if you have a lot of tuple enum variants with undocumented fields it becomes very noisy very quickly. As a real world example from one of my codebases:

pub enum RotationPolicy {
    /// Only rotate when [`RotatingFileWriter::rotate`] is called.
    Manual,
    /// Rotate when the active file exceeds this many bytes.
    SizeLimit(usize),
    /// Rotate periodically.
    Periodically(Period),
    /// Rotate both periodically and whenever the size limit is exceeded.
    SizeLimitAndPeriodically(usize, Period),
    /// A custom callback to determine when to rotate. Called after every write
    /// with the current active file size and age.
    Custom(Box<dyn FnMut(usize, Duration) -> bool>),
}

How it currently looks:

image

And with the superfluous sections removed:

image

I think we should get rid of any "Tuple Fields of Variant" section if that variants' fields are undocumented. It only adds noise and makes the documentation less readable in my opinion.

@orlp orlp changed the title rustdoc: Tuple Fields of Variant section is superfluous and noisy if all members are undocumented rustdoc: Tuple Fields of Variant section is superfluous and noisy if all fields are undocumented Nov 12, 2021
@camelid camelid added A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-discussion Category: Discussion or questions that doesn't represent real issues. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-discussion Category: Discussion or questions that doesn't represent real issues. labels Nov 20, 2021
@camelid camelid self-assigned this Nov 20, 2021
@camelid
Copy link
Member

camelid commented Nov 20, 2021

I wonder if instead we should just unconditionally get rid of the tuple fields in the header? Then it'd be consistent with struct fields. On the other hand, the header view is a bit easier to read in some ways since it matches source view.

cc @rust-lang/rustdoc: What do you think?

@jsha
Copy link
Contributor

jsha commented Nov 20, 2021

To clarify, you mean the heading of each variant, right? So e.g. SizeLimit(usize) would become SizeLimit, with a heading below that saying "Tuple Fields", and text below that saying 0: usize?

I prefer an approach where we keep SizeLimit(usize) as the heading, and say "if none of the tuple fields has a doccomment (the common case), we don't show the "Tuple Fields" section (as suggested in the top comment). Perhaps we should even deprecate comments on individual tuple fields? It seems quite uncommon to use, and rather awkward.

@GuillaumeGomez
Copy link
Member

I agree with @jsha proposition.

@Nemo157
Copy link
Member

Nemo157 commented Nov 21, 2021

Yep, in general I think if the fields need documentation people will generally be using struct-variants instead, so optimizing for doc-less tuple-variants makes sense.

@camelid
Copy link
Member

camelid commented Nov 21, 2021

Perhaps we should even deprecate comments on individual tuple fields? It seems quite uncommon to use, and rather awkward.

I disagree; we'd basically be removing expected behavior. I don't think we should force people to refactor their code just to add documentation. But optimizing for doc-less tuple variants (rather than enforcing it) seems potentially reasonable.

@GuillaumeGomez
Copy link
Member

Thanks to @camelid, I realized I misunderstood @jsha's comment. So let me update my comment:

To clarify, you mean the heading of each variant, right? So e.g. SizeLimit(usize) would become SizeLimit, with a heading below that saying "Tuple Fields", and text below that saying 0: usize?

I agree with this.

I prefer an approach where we keep SizeLimit(usize) as the heading, and say "if none of the tuplie fields has a doccomment (the common case), we don't show the "Tuple Fields" section (as suggested in the top comment).

I agree with this as well.

Perhaps we should even deprecate comments on individual tuple fields? It seems quite uncommon to use, and rather awkward.

I don't agree with this.

Hopefully I didn't miss something else...

@camelid
Copy link
Member

camelid commented Nov 21, 2021

To clarify, you mean the heading of each variant, right? So e.g. SizeLimit(usize) would become SizeLimit, with a heading below that saying "Tuple Fields", and text below that saying 0: usize?

I agree with this.

I prefer an approach where we keep SizeLimit(usize) as the heading, and say "if none of the tuplie fields has a doccomment (the common case), we don't show the "Tuple Fields" section (as suggested in the top comment).

I agree with this as well.

I don't understand; you agree with both? The two approaches are mutually exclusive IIUC.

@GuillaumeGomez
Copy link
Member

I don't have a preference is what I tried to say haha.

@jsha
Copy link
Contributor

jsha commented Dec 15, 2021

Since there's a PR up, I wanted to tidy up this issue thread. There was some confusion and back and forth above, but reading through it it seems like everyone who has chimed in either agrees with the original post's approach or doesn't have a preference. Since the PR (#91687) implements that approach, we're good.

@camelid
Copy link
Member

camelid commented Dec 15, 2021

I still think it's not great that now tuple fields and struct { ... } fields will be handled differently, but this seems like a good enough solution for now.

@camelid camelid removed their assignment Dec 15, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 10, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 12, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 13, 2022
@bors bors closed this as completed in 3e7bc08 Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants