Skip to content

Commit 6eb956f

Browse files
committed
Auto merge of rust-lang#84552 - GuillaumeGomez:open-impl-blocks-by-default, 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`
2 parents 61e1715 + 6c8969c commit 6eb956f

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ fn render_impl(
13051305
if let Some(use_absolute) = use_absolute {
13061306
write!(
13071307
w,
1308-
"<details class=\"rustdoc-toggle implementors-toggle\">\
1308+
"<details class=\"rustdoc-toggle implementors-toggle\" open>\
13091309
<summary>\
13101310
<h3 id=\"{}\" class=\"impl\"{}>\
13111311
<code class=\"in-band\">",
@@ -1334,7 +1334,7 @@ fn render_impl(
13341334
} else {
13351335
write!(
13361336
w,
1337-
"<details class=\"rustdoc-toggle implementors-toggle\">\
1337+
"<details class=\"rustdoc-toggle implementors-toggle\" open>\
13381338
<summary>\
13391339
<h3 id=\"{}\" class=\"impl\"{}>\
13401340
<code class=\"in-band\">{}</code>",

src/librustdoc/html/static/main.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ function hideThemeButtonState() {
480480
}
481481
// Open all ancestor <details> to make this element visible.
482482
openParentDetails(h3.parentNode);
483+
} else {
484+
openParentDetails(elem.parentNode);
483485
}
484486
}
485487
}
@@ -1412,9 +1414,9 @@ function hideThemeButtonState() {
14121414
// errors in mobile browsers).
14131415
if (e.tagName === "H2" || e.tagName === "H3") {
14141416
var nextTagName = e.nextElementSibling.tagName;
1415-
if (nextTagName == "H2" || nextTagName == "H3") {
1417+
if (nextTagName === "H2" || nextTagName === "H3") {
14161418
e.nextElementSibling.style.display = "flex";
1417-
} else {
1419+
} else if (nextTagName !== "DETAILS") {
14181420
e.nextElementSibling.style.display = "block";
14191421
}
14201422
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test ensures that the element corresponding to the hash is displayed.
2+
goto: file://|DOC_PATH|/struct.Foo.html#method.borrow
3+
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
4+
assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
5+
// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
6+
// a class selector.
7+
assert: ("#method\.borrow", {"display": "flex"})
8+
// We first check that the impl block is open by default.
9+
assert: ("#implementations + details", "open", "")
10+
// We collapse it.
11+
click: "#implementations + details > summary"
12+
// We check that it was collapsed as expected.
13+
assert-false: ("#implementations + details", "open", "")
14+
// To ensure that we will click on the currently hidden method.
15+
assert: (".sidebar-links > a", "must_use")
16+
click: ".sidebar-links > a"
17+
// We check that the impl block was opened as expected so that we can see the method.
18+
assert: ("#implementations + details", "open", "")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This test ensures that the impl blocks are open by default.
2+
goto: file://|DOC_PATH|/struct.Foo.html
3+
assert: ("#main > details.implementors-toggle", "open", "")

src/test/rustdoc-gui/nojs-attr-pos.goml

-5
This file was deleted.

0 commit comments

Comments
 (0)