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
Open
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
// (along with an `h2[@id="aliased-type"]` query),
// but unfortunatly python doesn't implement that.
//@ snapshot type-alias-code 'foo/type.TypeAlias.html' '//pre[@class="rust item-decl"][1]/code'
pub type TypeAlias = Type;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<code>pub type TypeAlias = <a class="enum" href="enum.Type.html" title="enum foo::Type">Type</a>;</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