Skip to content

Commit a5216cf

Browse files
Unify inherent impl blocks by wrapping them into a div
1 parent a64180f commit a5216cf

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
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/duplicate_impls/issue-33054.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @has - '//h3[@class="code-header in-band"]' 'impl Foo'
33
// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
44
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1
5-
// @count - '//*[@id="main-content"]/details/summary/*[@class="impl has-srclink"]' 1
5+
// @count - '//*[@id="main-content"]/div[@id="implementations-list"]/details/summary/*[@class="impl has-srclink"]' 1
66
// @has issue_33054/impls/bar/trait.Bar.html
77
// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
88
// @count - '//*[@class="struct"]' 1

0 commit comments

Comments
 (0)