Skip to content

Commit d151ed8

Browse files
Rollup merge of #85280 - jsha:move-trait-toggles, r=GuillaumeGomez
Toggle-wrap items differently than top-doc. This makes sure things like trait methods get wrapped at the `<h3><code>` level rather than at the `.docblock` level. Also it ensures that only the actual top documentation gets the `.top-doc` class. Fixes #85167 Before: ![image](https://user-images.githubusercontent.com/220205/117743384-98790200-b1bb-11eb-8804-588530842514.png) https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read After: ![image](https://user-images.githubusercontent.com/220205/118410882-98a75080-b646-11eb-949d-ca688bab6923.png)
2 parents 07d11cf + 6696a60 commit d151ed8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/librustdoc/html/render/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,11 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
509509
info!("Documenting {}", name);
510510
}
511511
document_item_info(w, cx, item, parent);
512-
document_full_collapsible(w, item, cx);
512+
if parent.is_none() {
513+
document_full_collapsible(w, item, cx);
514+
} else {
515+
document_full(w, item, cx);
516+
}
513517
}
514518

515519
/// Render md_text as markdown.

src/librustdoc/html/render/print_item.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,13 @@ 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>");
581582
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id,);
582583
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
583584
w.write_str("</code>");
584585
render_stability_since(w, m, t, cx.tcx());
585586
write_srclink(cx, m, w);
586-
w.write_str("</h3>");
587+
w.write_str("</h3></summary>");
587588
document(w, cx, m, Some(t));
588589
}
589590

src/test/rustdoc/toggle-trait-fn.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/trait.Foo.html
4+
// @has - '//details[@class="rustdoc-toggle"]//code' 'bar'
5+
pub trait Foo {
6+
fn bar() -> ();
7+
}

0 commit comments

Comments
 (0)