Skip to content

Commit 668c607

Browse files
authored
Rollup merge of rust-lang#94740 - GuillaumeGomez:unify-impl-blocks, r=notriddle
Unify impl blocks by wrapping them into a div The blanket and "auto traits" sections are wrapped into a `div` with an ID. This PR fixes this incoherence by wrapping each impl section (the "deref impl" and the "inherent impl" sections were missing it). It'll also make some tests simpler to write. r? ```@notriddle```
2 parents fca8dba + fbd9c28 commit 668c607

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed

src/librustdoc/html/markdown.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ fn init_id_map() -> FxHashMap<String, usize> {
14601460
map.insert("provided-methods".to_owned(), 1);
14611461
map.insert("implementors".to_owned(), 1);
14621462
map.insert("synthetic-implementors".to_owned(), 1);
1463+
map.insert("implementations-list".to_owned(), 1);
14631464
map.insert("trait-implementations-list".to_owned(), 1);
14641465
map.insert("synthetic-implementations-list".to_owned(), 1);
14651466
map.insert("blanket-implementations-list".to_owned(), 1);

src/librustdoc/html/render/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1065,14 +1065,15 @@ fn render_assoc_items_inner(
10651065
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
10661066
if !non_trait.is_empty() {
10671067
let mut tmp_buf = Buffer::empty_from(w);
1068-
let render_mode = match what {
1068+
let (render_mode, id) = match what {
10691069
AssocItemRender::All => {
10701070
tmp_buf.write_str(
10711071
"<h2 id=\"implementations\" class=\"small-section-header\">\
1072-
Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
1073-
</h2>",
1072+
Implementations\
1073+
<a href=\"#implementations\" class=\"anchor\"></a>\
1074+
</h2>",
10741075
);
1075-
RenderMode::Normal
1076+
(RenderMode::Normal, "implementations-list".to_owned())
10761077
}
10771078
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
10781079
let id =
@@ -1090,7 +1091,7 @@ fn render_assoc_items_inner(
10901091
trait_ = trait_.print(cx),
10911092
type_ = type_.print(cx),
10921093
);
1093-
RenderMode::ForDeref { mut_: deref_mut_ }
1094+
(RenderMode::ForDeref { mut_: deref_mut_ }, cx.derive_id(id))
10941095
}
10951096
};
10961097
let mut impls_buf = Buffer::empty_from(w);
@@ -1115,7 +1116,9 @@ fn render_assoc_items_inner(
11151116
}
11161117
if !impls_buf.is_empty() {
11171118
w.push_buffer(tmp_buf);
1119+
write!(w, "<div id=\"{}\">", id);
11181120
w.push_buffer(impls_buf);
1121+
w.write_str("</div>");
11191122
}
11201123
}
11211124

@@ -1146,7 +1149,8 @@ fn render_assoc_items_inner(
11461149
write!(
11471150
w,
11481151
"<h2 id=\"trait-implementations\" class=\"small-section-header\">\
1149-
Trait Implementations<a href=\"#trait-implementations\" class=\"anchor\"></a>\
1152+
Trait Implementations\
1153+
<a href=\"#trait-implementations\" class=\"anchor\"></a>\
11501154
</h2>\
11511155
<div id=\"trait-implementations-list\">{}</div>",
11521156
impls

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ function hideThemeButtonState() {
741741
} else {
742742
addClass(innerToggle, "will-expand");
743743
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) {
744-
if (e.parentNode.id !== MAIN_ID ||
744+
if (e.parentNode.id !== "implementations-list" ||
745745
(!hasClass(e, "implementors-toggle") &&
746746
!hasClass(e, "type-contents-toggle")))
747747
{

src/test/rustdoc-gui/docblock-table-overflow.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"})
1212

1313
// Logically, the ".docblock" and the "<p>" should have the same scroll width.
1414
compare-elements-property: (
15-
"#implementations + details .docblock",
16-
"#implementations + details .docblock > p",
15+
"#implementations-list > details .docblock",
16+
"#implementations-list > details .docblock > p",
1717
["scrollWidth"],
1818
)
19-
assert-property: ("#implementations + details .docblock", {"scrollWidth": "801"})
19+
assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "801"})
2020
// However, since there is overflow in the <table>, its scroll width is bigger.
21-
assert-property: ("#implementations + details .docblock table", {"scrollWidth": "1573"})
21+
assert-property: ("#implementations-list > details .docblock table", {"scrollWidth": "1573"})

src/test/rustdoc-gui/hash-item-expansion.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow
33
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
44
assert-attribute: ("#blanket-implementations-list > details:nth-child(2)", {"open": ""})
55
// We first check that the impl block is open by default.
6-
assert-attribute: ("#implementations + details", {"open": ""})
6+
assert-attribute: ("#implementations-list details", {"open": ""})
77
// To ensure that we will click on the currently hidden method.
88
assert-text: (".sidebar-elems section .block li > a", "must_use")
99
click: ".sidebar-elems section .block li > a"
1010
// We check that the impl block was opened as expected so that we can see the method.
11-
assert-attribute: ("#implementations + details", {"open": ""})
11+
assert-attribute: ("#implementations-list > details", {"open": ""})
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This test ensures that the impl blocks are open by default.
22
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
3-
assert-attribute: ("#main-content > details.implementors-toggle", {"open": ""})
3+
assert-attribute: ("#implementations-list details.implementors-toggle", {"open": ""})

src/test/rustdoc-gui/toggle-docs-mobile.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ assert-attribute: (".top-doc", {"open": ""})
1414
// Assert the position of the toggle on the top doc block.
1515
assert-position: (".top-doc summary::before", {"x": 4})
1616
// Assert the position of the toggle on the impl block.
17-
assert-position: ("#implementations + details > summary::before", {"x": 4})
17+
assert-position: ("#implementations-list > details > summary::before", {"x": 4})
1818
// Assert the position of the toggle on a method.
1919
assert-position: (
2020
"#trait-implementations-list .impl-items .method-toggle > summary::before",

src/test/rustdoc-gui/toggle-docs.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ wait-for: 50
2424
assert-text: ("#toggle-all-docs", "[+]")
2525
// We check that all <details> are collapsed (except for the impl block ones).
2626
assert-attribute-false: ("details.rustdoc-toggle:not(.implementors-toggle)", {"open": ""}, ALL)
27-
assert-attribute: ("details.rustdoc-toggle.implementors-toggle", {"open": ""})
27+
assert-attribute: ("#implementations-list > details.implementors-toggle", {"open": ""})
2828
// We now check that the other impl blocks are collapsed.
2929
assert-attribute-false: (
3030
"#blanket-implementations-list > details.rustdoc-toggle.implementors-toggle",

src/test/rustdoc/duplicate_impls/issue-33054.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// ignore-tidy-linelength
2+
13
// @has issue_33054/impls/struct.Foo.html
24
// @has - '//h3[@class="code-header in-band"]' 'impl Foo'
35
// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
46
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1
5-
// @count - '//*[@id="main-content"]/details/summary/*[@class="impl has-srclink"]' 1
7+
// @count - '//*[@id="main-content"]/div[@id="implementations-list"]/details/summary/*[@class="impl has-srclink"]' 1
68
// @has issue_33054/impls/bar/trait.Bar.html
79
// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
810
// @count - '//*[@class="struct"]' 1

0 commit comments

Comments
 (0)