Skip to content

Commit

Permalink
Mark the "#[default]" variant for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed Oct 18, 2023
1 parent 94ba57c commit bd0cb1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <span class=\"stab default\">Default</span>");
}
w.write_str("</h3></section>");

let heading_and_fields = match &variant_data.kind {
Expand Down
8 changes: 8 additions & 0 deletions tests/rustdoc/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit bd0cb1e

Please sign in to comment.