Skip to content

rustdoc: show attributes on enum variants #142987

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

@lolbinarycat lolbinarycat commented Jun 24, 2025

mostly for #[non_exhaustive]

unsure if there's any attributes we should take care to not include, it could use render_code_attribute and is_non_exhaustive instead, if that is a concern.

fixes #142599

@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 24, 2025
@lolbinarycat lolbinarycat force-pushed the rustdoc-non_exhaustive-enum-v-142599 branch from 232bdaf to a73c70e Compare June 24, 2025 23:07
@GuillaumeGomez
Copy link
Member

Looks good to me, thanks! Since @fmease opened the issue, I'll let them take a look before r+ing.

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.

Attribute-related changes look fine to me.

It might be worth noting that for non-exhaustive structs, below the "introductory code snippet" we say Fields (Non-exhaustive) and have a <details> section explaining what that implies whereas for enum variants, we just say Fields but we do have that same <details> section. Not sure if y'all want to address that in this PR.

(Does this show up in Aliased Type sections? Just curious. I know that we only allowlist repr for aliased enums and structs and we should include #[non_exhaustive] at some point but that's a another story for another day).

@GuillaumeGomez
Copy link
Member

Normally it should since #140863 which unified alias rendering with the other ADTs. However I suppose adding a test to ensure it is rendering as expected would be a good idea.

Can you add a type alias on the enum in your rustdoc test @lolbinarycat please?

@lolbinarycat lolbinarycat force-pushed the rustdoc-non_exhaustive-enum-v-142599 branch from a73c70e to 4bece45 Compare June 25, 2025 18:47
@lolbinarycat
Copy link
Contributor Author

Yes it shows up in the aliased type. Added a test for that (unfortunately I couldn't make it super robust due to not having access to all of XPath)


// we would love to use the `following-sibling::` axis
// (along with an `h2[@id="aliased-type"]` query),
// but unfortunatly python doesn't implement that.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// but unfortunatly python doesn't implement that.
// but unfortunately python doesn't implement that.

@@ -0,0 +1 @@
<code>pub type TypeAlias = <a class="enum" href="enum.Type.html" title="enum foo::Type">Type</a>;</code>
Copy link
Member

Choose a reason for hiding this comment

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

It's not what we want to check. It's the declaration of the aliased pub enum and in particular to ensure that its variants have the attributes displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, yeah that's just a simple mistake that wouldn't have happened if we had access to following-sibling::, will fix.

mostly for #[non_exhaustive]
@lolbinarycat lolbinarycat force-pushed the rustdoc-non_exhaustive-enum-v-142599 branch from 4bece45 to b2be01c Compare June 26, 2025 17:33
Variant,
}

// we would love to use the `following-sibling::` axis
Copy link
Member

Choose a reason for hiding this comment

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

Does this comment still make sense? Current code is fine and I'm not sure to understand what follow-sibling added value would be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would allow us to select "the code block in the aliased type section" instead of "the second code block" which would be robust against us adding additional code blocks or rearranging them.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough!

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

📌 Commit b2be01c has been approved by GuillaumeGomez

It is now in the queue for this repository.

@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 Jun 27, 2025
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 27, 2025
…e-enum-v-142599, r=GuillaumeGomez

rustdoc: show attributes on enum variants

mostly for #[non_exhaustive]

unsure if there's any attributes we should take care to *not* include, it could use `render_code_attribute` and `is_non_exhaustive` instead, if that is a concern.

fixes rust-lang#142599
bors added a commit that referenced this pull request Jun 27, 2025
…rors

Rollup of 8 pull requests

Successful merges:

 - #139858 (New const traits syntax)
 - #140809 (Reduce special casing for the panic runtime)
 - #142963 (Skip unnecessary components in x64 try builds)
 - #142974 (Update stage0 to 1.89.0-beta.1)
 - #142987 (rustdoc: show attributes on enum variants)
 - #143002 (tests: Require `run-fail` ui tests to have an exit code (`SIGABRT` not ok))
 - #143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - #143096 (tag_for_variant: properly pass TypingEnv)

r? `@ghost`
`@rustbot` modify labels: rollup
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc doesn't render #[non_exhaustive] on enum variants
5 participants