diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-09 18:47:25 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-25 15:10:23 +0200 |
| commit | 4f3dd7b0180b1212aab607202ec6aa0d4fabb323 (patch) | |
| tree | 0dd450077b4f8cf956feb90c3e90f221fd22dd7e /src/librustdoc/html/render/mod.rs | |
| parent | eb9f05481be266598527ba9b5eb890cc56555733 (diff) | |
| download | rust-4f3dd7b0180b1212aab607202ec6aa0d4fabb323.tar.gz rust-4f3dd7b0180b1212aab607202ec6aa0d4fabb323.zip | |
Tweak attribute rendering depending on wether or not it is a type alias
Diffstat (limited to 'src/librustdoc/html/render/mod.rs')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 6b4fd3cd834..f155ea52040 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1201,11 +1201,31 @@ fn render_attributes_in_pre(it: &clean::Item, prefix: &str, cx: &Context<'_>) -> }) } +struct CodeAttribute(String); + +impl CodeAttribute { + fn render_into(self, w: &mut impl fmt::Write) { + write!(w, "<div class=\"code-attribute\">{}</div>", self.0).unwrap(); + } +} + // When an attribute is rendered inside a <code> tag, it is formatted using // a div to produce a newline after it. fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, cx: &Context<'_>) { for attr in it.attributes_and_repr(cx.tcx(), cx.cache(), false) { - write!(w, "<div class=\"code-attribute\">{attr}</div>").unwrap(); + CodeAttribute(attr).render_into(w); + } +} + +/// used for type aliases to only render their `repr` attribute. +fn render_repr_attributes_in_code( + w: &mut impl fmt::Write, + cx: &Context<'_>, + def_id: DefId, + item_type: ItemType, +) { + if let Some(repr) = clean::repr_attributes(cx.tcx(), cx.cache(), def_id, item_type) { + CodeAttribute(repr).render_into(w); } } |
