diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 67ccf2137bf6e..b82967b403d65 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1305,7 +1305,7 @@ fn render_impl(
if let Some(use_absolute) = use_absolute {
write!(
w,
- "\
+ "\
\
\
",
@@ -1334,7 +1334,7 @@ fn render_impl(
} else {
write!(
w,
- "\
+ "\
\
\
{}
",
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 2e3e148eaf695..9f7cbca9052d0 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -480,6 +480,8 @@ function hideThemeButtonState() {
}
// Open all ancestor to make this element visible.
openParentDetails(h3.parentNode);
+ } else {
+ openParentDetails(elem.parentNode);
}
}
}
@@ -1422,9 +1424,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";
}
}
diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml
new file mode 100644
index 0000000000000..d736d15d184a3
--- /dev/null
+++ b/src/test/rustdoc-gui/hash-item-expansion.goml
@@ -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", "")
diff --git a/src/test/rustdoc-gui/impl-default-expansion.goml b/src/test/rustdoc-gui/impl-default-expansion.goml
new file mode 100644
index 0000000000000..686d98f9736e4
--- /dev/null
+++ b/src/test/rustdoc-gui/impl-default-expansion.goml
@@ -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", "")
diff --git a/src/test/rustdoc-gui/nojs-attr-pos.goml b/src/test/rustdoc-gui/nojs-attr-pos.goml
deleted file mode 100644
index 35daa4cb9e322..0000000000000
--- a/src/test/rustdoc-gui/nojs-attr-pos.goml
+++ /dev/null
@@ -1,5 +0,0 @@
-// Check that the attributes are well positioned when javascript is disabled (since
-// there is no toggle to display)
-javascript: false
-goto: file://|DOC_PATH|/struct.Foo.html
-assert: (".attributes", {"margin-left": "0px"})