Skip to content

Commit

Permalink
Auto merge of rust-lang#84552 - GuillaumeGomez:open-impl-blocks-by-de…
Browse files Browse the repository at this point in the history
…fault, r=jsha

Open impl blocks by default

Fixes rust-lang#84558.
Part of rust-lang#84422.

As you can see on https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html, impl blocks are currently not open by default whereas they should.

I also realized that a test was outdated so I removed it and opened rust-lang#84550 because it seems like the rustdoc-gui test suite isn't run on CI...

cc `@jyn514`
r? `@jsha`
  • Loading branch information
bors committed Apr 27, 2021
2 parents 61e1715 + 6c8969c commit 6eb956f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ fn render_impl(
if let Some(use_absolute) = use_absolute {
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\">\
"<details class=\"rustdoc-toggle implementors-toggle\" open>\
<summary>\
<h3 id=\"{}\" class=\"impl\"{}>\
<code class=\"in-band\">",
Expand Down Expand Up @@ -1334,7 +1334,7 @@ fn render_impl(
} else {
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\">\
"<details class=\"rustdoc-toggle implementors-toggle\" open>\
<summary>\
<h3 id=\"{}\" class=\"impl\"{}>\
<code class=\"in-band\">{}</code>",
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ function hideThemeButtonState() {
}
// Open all ancestor <details> to make this element visible.
openParentDetails(h3.parentNode);
} else {
openParentDetails(elem.parentNode);
}
}
}
Expand Down Expand Up @@ -1412,9 +1414,9 @@ function hideThemeButtonState() {
// errors in mobile browsers).
if (e.tagName === "H2" || e.tagName === "H3") {
var nextTagName = e.nextElementSibling.tagName;
if (nextTagName == "H2" || nextTagName == "H3") {
if (nextTagName === "H2" || nextTagName === "H3") {
e.nextElementSibling.style.display = "flex";
} else {
} else if (nextTagName !== "DETAILS") {
e.nextElementSibling.style.display = "block";
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc-gui/hash-item-expansion.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This test ensures that the element corresponding to the hash is displayed.
goto: file://|DOC_PATH|/struct.Foo.html#method.borrow
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
// a class selector.
assert: ("#method\.borrow", {"display": "flex"})
// We first check that the impl block is open by default.
assert: ("#implementations + details", "open", "")
// We collapse it.
click: "#implementations + details > summary"
// We check that it was collapsed as expected.
assert-false: ("#implementations + details", "open", "")
// To ensure that we will click on the currently hidden method.
assert: (".sidebar-links > a", "must_use")
click: ".sidebar-links > a"
// We check that the impl block was opened as expected so that we can see the method.
assert: ("#implementations + details", "open", "")
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/impl-default-expansion.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This test ensures that the impl blocks are open by default.
goto: file://|DOC_PATH|/struct.Foo.html
assert: ("#main > details.implementors-toggle", "open", "")
5 changes: 0 additions & 5 deletions src/test/rustdoc-gui/nojs-attr-pos.goml

This file was deleted.

0 comments on commit 6eb956f

Please sign in to comment.