diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-05-26 14:35:39 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-05-26 14:35:39 +0200 |
| commit | f9499ea9f55926bd53cd6897878a05f7982dc48f (patch) | |
| tree | 2d74bf21754c520e9bb1acda00b7c7af1b4ea123 | |
| parent | fbf1b1a7193cda17008ab590e06ad28d9924023b (diff) | |
| download | rust-f9499ea9f55926bd53cd6897878a05f7982dc48f.tar.gz rust-f9499ea9f55926bd53cd6897878a05f7982dc48f.zip | |
* Fix bug where some <details> tags were not closed.
* Don't generate a <details> if there is no documentation
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 50153ac14a2..e06168c708c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -578,14 +578,23 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra info!("Documenting {} on {:?}", name, t.name); let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); - write!(w, "<details class=\"rustdoc-toggle\" open><summary>"); - write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,); + let mut content = Buffer::empty_from(w); + document(&mut content, cx, m, Some(t)); + let toggled = !content.is_empty(); + if toggled { + write!(w, "<details class=\"rustdoc-toggle\" open><summary>"); + } + write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id); render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx); w.write_str("</code>"); render_stability_since(w, m, t, cx.tcx()); write_srclink(cx, m, w); - w.write_str("</h3></summary>"); - document(w, cx, m, Some(t)); + w.write_str("</h3>"); + if toggled { + write!(w, "</summary>"); + w.push_buffer(content); + write!(w, "</details>"); + } } if !types.is_empty() { |
