From bd0cb1ee98ef0d29741c3680666a62b7dba2ab6e Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Tue, 17 Oct 2023 23:03:55 +0200 Subject: [PATCH] Mark the "#[default]" variant for enums --- src/librustdoc/html/render/print_item.rs | 3 +++ tests/rustdoc/attributes.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index f6432dc61ae06..f0b53259b5cb8 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1618,6 +1618,9 @@ fn item_variants( if let clean::VariantKind::Tuple(ref s) = variant_data.kind { write!(w, "({})", print_tuple_struct_fields(cx, s)); } + if variant.attrs.other_attrs.iter().any(|a| a.has_name(kw::Default)) { + w.write_str(" Default"); + } w.write_str(""); let heading_and_fields = match &variant_data.kind { diff --git a/tests/rustdoc/attributes.rs b/tests/rustdoc/attributes.rs index 86333c7534a3f..809c621740366 100644 --- a/tests/rustdoc/attributes.rs +++ b/tests/rustdoc/attributes.rs @@ -11,3 +11,11 @@ pub extern "C" fn g() {} // @has foo/struct.Repr.html '//pre[@class="rust item-decl"]' '#[repr(C, align(8))]' #[repr(C, align(8))] pub struct Repr; + +// @has foo/enum.Enum.html '//section[@id="variant.Foo"]' 'Default' +#[derive(Default)] +pub enum Enum { + #[default] + Foo, + Bar, +}