Skip to content
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
24 changes: 21 additions & 3 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,13 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
)
}

fn print_field_attrs(&self, field: &'a clean::Item) -> impl Display {
fmt::from_fn(move |w| {
render_attributes_in_code(w, field, "", self.cx);
Ok(())
})
}

fn document_field(&self, field: &'a clean::Item) -> impl Display {
document(self.cx, field, Some(self.it), HeadingOffset::H3)
}
Expand Down Expand Up @@ -1770,6 +1777,7 @@ fn item_variants(
)
.maybe_display()
)?;
render_attributes_in_code(w, variant, "", cx);
if let clean::VariantItem(ref var) = variant.kind
&& let clean::VariantKind::CLike = var.kind
{
Expand Down Expand Up @@ -1843,7 +1851,12 @@ fn item_variants(
"<div class=\"sub-variant-field\">\
<span id=\"{id}\" class=\"section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{f}: {t}</code>\
<code>"
)?;
render_attributes_in_code(w, field, "", cx);
write!(
w,
"{f}: {t}</code>\
</span>\
{doc}\
</div>",
Expand Down Expand Up @@ -2079,10 +2092,15 @@ fn item_fields(
w,
"<span id=\"{id}\" class=\"{item_type} section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{field_name}: {ty}</code>\
<code>",
item_type = ItemType::StructField,
)?;
render_attributes_in_code(w, field, "", cx);
write!(
w,
"{field_name}: {ty}</code>\
</span>\
{doc}",
item_type = ItemType::StructField,
ty = ty.print(cx),
doc = document(cx, field, Some(it), HeadingOffset::H3),
)?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/item_union.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2 id="fields" class="fields section-header"> {# #}
{% let name = field.name.expect("union field name") %}
<span id="structfield.{{ name }}" class="{{ ItemType::StructField +}} section-header"> {# #}
<a href="#structfield.{{ name }}" class="anchor field">§</a> {# #}
<code>{{ name }}: {{+ self.print_ty(ty)|safe }}</code> {# #}
<code>{{+ self.print_field_attrs(field)|safe }}{{ name }}: {{+ self.print_ty(ty)|safe }}</code> {# #}
</span>
{% if let Some(stability_class) = self.stability_field(field) %}
<span class="stab {{ stability_class }}"></span>
Expand Down
4 changes: 4 additions & 0 deletions tests/rustdoc/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ macro_rules! macro_rule {
#[unsafe(link_section = "enum")]
pub enum Enum {
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "a")]'
//@ has - '//*[@class="variants"]//*[@class="code-attribute"]' '#[unsafe(link_section = "a")]'
#[unsafe(link_section = "a")]
A,
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "quz")]'
//@ has - '//*[@class="variants"]//*[@class="code-attribute"]' '#[unsafe(link_section = "quz")]'
#[unsafe(link_section = "quz")]
Quz {
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "b")]'
//@ has - '//*[@class="variants"]//*[@class="code-attribute"]' '#[unsafe(link_section = "b")]'
#[unsafe(link_section = "b")]
b: (),
},
Expand Down Expand Up @@ -66,6 +69,7 @@ pub union Union {
#[unsafe(link_section = "struct")]
pub struct Struct {
//@ has 'foo/struct.Struct.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "x")]'
//@ has - '//*[@id="structfield.x"]//*[@class="code-attribute"]' '#[unsafe(link_section = "x")]'
#[unsafe(link_section = "x")]
pub x: u32,
y: f32,
Expand Down
Loading