Skip to content

Commit f9499ea

Browse files
* Fix bug where some <details> tags were not closed.
* Don't generate a <details> if there is no documentation
1 parent fbf1b1a commit f9499ea

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustdoc/html/render/print_item.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,23 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
578578
info!("Documenting {} on {:?}", name, t.name);
579579
let item_type = m.type_();
580580
let id = cx.derive_id(format!("{}.{}", item_type, name));
581-
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
582-
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,);
581+
let mut content = Buffer::empty_from(w);
582+
document(&mut content, cx, m, Some(t));
583+
let toggled = !content.is_empty();
584+
if toggled {
585+
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
586+
}
587+
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id);
583588
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
584589
w.write_str("</code>");
585590
render_stability_since(w, m, t, cx.tcx());
586591
write_srclink(cx, m, w);
587-
w.write_str("</h3></summary>");
588-
document(w, cx, m, Some(t));
592+
w.write_str("</h3>");
593+
if toggled {
594+
write!(w, "</summary>");
595+
w.push_buffer(content);
596+
write!(w, "</details>");
597+
}
589598
}
590599

591600
if !types.is_empty() {

0 commit comments

Comments
 (0)