Rollup merge of #84320 - jsha:details-implementors, r=Manishearth,Nemo157,GuillaumeGomez
Use details tag for trait implementors. Part of #83332 and following on from #83337 and #83355. This removes one category of JS-generated toggles (implementors), and replaces them with a `<details>` tag. This simplifies the JS, and fixes some bugs where things that were supposed to be hidden by the toggle were not hidden. Compare https://hoffman-andrews.com/rust/details-implementors/std/io/trait.Read.html#impl-Read vs https://doc.rust-lang.org/nightly/std/io/trait.Read.html#implementors. This introduces a `left: -23px` to put the toggle in the correct place, matching the current style for `.collapse-toggle`. It's worth noting this introduces a slight behavior change: since the entire line is now a `<summary>`, any part of the line is clickable. So for instance, in `impl Read for File`, clicking `impl` or `for` will collapse / expand the docs. Clicking `Read` or `File` still links to the appropriate documentation as before.
This commit is contained in:
@@ -1284,6 +1284,7 @@ fn render_impl(
|
||||
let cache = cx.cache();
|
||||
let traits = &cache.traits;
|
||||
let trait_ = i.trait_did_full(cache).map(|did| &traits[&did]);
|
||||
let mut close_tags = String::new();
|
||||
|
||||
if render_mode == RenderMode::Normal {
|
||||
let id = cx.derive_id(match i.inner_impl().trait_ {
|
||||
@@ -1302,7 +1303,12 @@ fn render_impl(
|
||||
format!(" aliases=\"{}\"", aliases.join(","))
|
||||
};
|
||||
if let Some(use_absolute) = use_absolute {
|
||||
write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases);
|
||||
write!(
|
||||
w,
|
||||
"<details class=\"rustdoc-toggle implementors-toggle\"><summary><h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">",
|
||||
id, aliases
|
||||
);
|
||||
close_tags.insert_str(0, "</details>");
|
||||
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
|
||||
if show_def_docs {
|
||||
for it in &i.inner_impl().items {
|
||||
@@ -1325,11 +1331,12 @@ fn render_impl(
|
||||
} else {
|
||||
write!(
|
||||
w,
|
||||
"<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
|
||||
"<details class=\"rustdoc-toggle implementors-toggle\"><summary><h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
|
||||
id,
|
||||
aliases,
|
||||
i.inner_impl().print(false, cx)
|
||||
);
|
||||
close_tags.insert_str(0, "</details>");
|
||||
}
|
||||
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
||||
render_stability_since_raw(
|
||||
@@ -1341,6 +1348,7 @@ fn render_impl(
|
||||
);
|
||||
write_srclink(cx, &i.impl_item, w);
|
||||
w.write_str("</h3>");
|
||||
w.write_str("</summary>");
|
||||
|
||||
if trait_.is_some() {
|
||||
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
|
||||
@@ -1542,6 +1550,7 @@ fn render_impl(
|
||||
}
|
||||
|
||||
w.write_str("<div class=\"impl-items\">");
|
||||
close_tags.insert_str(0, "</div>");
|
||||
for trait_item in &i.inner_impl().items {
|
||||
doc_impl_item(
|
||||
w,
|
||||
@@ -1612,7 +1621,7 @@ fn render_impl(
|
||||
);
|
||||
}
|
||||
}
|
||||
w.write_str("</div>");
|
||||
w.write_str(&close_tags);
|
||||
}
|
||||
|
||||
fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||
|
||||
Reference in New Issue
Block a user