Skip to content

rustdoc: How to render struct variants with no visible fields? #118195

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

Closed
Kyuuhachi opened this issue Nov 23, 2023 · 1 comment · Fixed by #118600
Closed

rustdoc: How to render struct variants with no visible fields? #118195

Kyuuhachi opened this issue Nov 23, 2023 · 1 comment · Fixed by #118600
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

@Kyuuhachi
Copy link
Contributor

While working on #118192, I noticed that struct variants with no (visible) fields look kinda awkward.

pub enum MyEnum {
	/// A variant with no fields
	A {},
	/// A variant with hidden fields
	B { #[doc(hidden)] a: u8 },
}

rendering of the above code snippet

The Fields heading takes a lot of space without adding particularly much to the content. The easiest solution would be to just remove the heading, but that would show no indication that there exist private fields. The same issue exists in top-level structs as well, but there it is mitigated by having the definition in the code block just above, while for enums there can be a sizeable distance between the two.

Any thoughts? Am I just overthinking the whole thing?

@Kyuuhachi Kyuuhachi added the C-bug Category: This is a bug. label Nov 23, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 23, 2023
@fmease fmease added 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. A-rustdoc-ui Area: Rustdoc UI (generated HTML) and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 23, 2023
@GuillaumeGomez
Copy link
Member

No this is a very good point. If there are no fields, we shouldn't add the "Fields" heading. Sending a fix.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 4, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 4, 2023
…otriddle

[rustdoc] Don't generate the "Fields" heading if there is no field displayed

Fixes rust-lang#118195.

If no field is displayed, we should not generate the `Fields` heading in enum struct variants.

r? `@notriddle`
@bors bors closed this as completed in baa3f96 Dec 5, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 5, 2023
Rollup merge of rust-lang#118600 - GuillaumeGomez:fields-heading, r=notriddle

[rustdoc] Don't generate the "Fields" heading if there is no field displayed

Fixes rust-lang#118195.

If no field is displayed, we should not generate the `Fields` heading in enum struct variants.

r? ``@notriddle``
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.

4 participants