Rollup merge of #85722 - GuillaumeGomez:trait-toggle, r=jsha
Fix trait methods' toggle A `<details>` tag wasn't closed on trait methods, which created broken DOM. I also used this occasion to only generate the toggle in case there is documentation on the method. r? `@jsha`
This commit is contained in:
commit
6ac83e1808
2 changed files with 18 additions and 5 deletions
|
@ -578,14 +578,23 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
info!("Documenting {} on {:?}", name, t.name);
|
info!("Documenting {} on {:?}", name, t.name);
|
||||||
let item_type = m.type_();
|
let item_type = m.type_();
|
||||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||||
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
|
let mut content = Buffer::empty_from(w);
|
||||||
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,);
|
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);
|
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
|
||||||
w.write_str("</code>");
|
w.write_str("</code>");
|
||||||
render_stability_since(w, m, t, cx.tcx());
|
render_stability_since(w, m, t, cx.tcx());
|
||||||
write_srclink(cx, m, w);
|
write_srclink(cx, m, w);
|
||||||
w.write_str("</h3></summary>");
|
w.write_str("</h3>");
|
||||||
document(w, cx, m, Some(t));
|
if toggled {
|
||||||
|
write!(w, "</summary>");
|
||||||
|
w.push_buffer(content);
|
||||||
|
write!(w, "</details>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !types.is_empty() {
|
if !types.is_empty() {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
#![crate_name = "foo"]
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
// @has foo/trait.Foo.html
|
// @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 {
|
pub trait Foo {
|
||||||
fn bar() -> ();
|
fn bar() -> ();
|
||||||
|
/// hello
|
||||||
|
fn foo();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue