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
17 changes: 13 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/test/rustdoc/toggle-trait-fn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#![crate_name = "foo"]

// @has foo/trait.Foo.html
// @has - '//details[@class="rustdoc-toggle"]//code' 'bar'
// @!has - '//details[@class="rustdoc-toggle"]//code' 'bar'
// @has - '//code' 'bar'
// @has - '//details[@class="rustdoc-toggle"]//code' 'foo'
pub trait Foo {
fn bar() -> ();
/// hello
fn foo();
}