Skip to content

rustdoc: show attributes on enum variants #142987

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ fn render_enum_fields(
if v.is_stripped() {
continue;
}
write!(w, "{}", render_attributes_in_pre(v, TAB, cx))?;
w.write_str(TAB)?;
match v.kind {
clean::VariantItem(ref var) => match var.kind {
Expand Down
17 changes: 17 additions & 0 deletions tests/rustdoc/enum/enum-variant-non_exhaustive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// regression test for https://github.com/rust-lang/rust/issues/142599

#![crate_name = "foo"]

//@ snapshot type-code 'foo/enum.Type.html' '//pre[@class="rust item-decl"]/code'
pub enum Type {
#[non_exhaustive]
// attribute that should not be shown
#[warn(unsafe_code)]
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!

// (along with an `h2[@id="aliased-type"]` query),
// but unfortunately python doesn't implement that.
//@ snapshot type-alias-code 'foo/type.TypeAlias.html' '//pre[@class="rust item-decl"][2]/code'
pub type TypeAlias = Type;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<code>pub enum TypeAlias {
#[non_exhaustive]
Variant,
}</code>
4 changes: 4 additions & 0 deletions tests/rustdoc/enum/enum-variant-non_exhaustive.type-code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<code>pub enum Type {
#[non_exhaustive]
Variant,
}</code>
Loading