Skip to content

Commit 7a341ff

Browse files
Rollup merge of #110964 - notriddle:notriddle/deref-impl, r=GuillaumeGomez
rustdoc: fix weird margins between Deref impl items ## Before ![image](https://user-images.githubusercontent.com/1593513/235245977-90770591-22c1-4a27-9464-248a3729a2b7.png) ## After ![image](https://user-images.githubusercontent.com/1593513/235246009-0e83113e-42b7-4e29-981d-969f9d20af01.png) ## Description In the old setup, if the dereffed-to item has multiple impl blocks, each one gets its own `div.impl-items` in the section, but there are no headers separating them. Since the last method in a `div.impl-items` has no bottom margin, and there are no margins between these divs, there is no margin between the last method of one impl and the first method of the following impl. This patch fixes it by simplifying the HTML. Each Deref block gets exactly one `div.impl-items`, no matter how many impl blocks it actually has.
2 parents 4a702c0 + 2299ba1 commit 7a341ff

13 files changed

+55
-6
lines changed

src/librustdoc/html/render/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,10 @@ fn render_assoc_items_inner(
11551155
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
11561156
if !non_trait.is_empty() {
11571157
let mut tmp_buf = Buffer::html();
1158-
let (render_mode, id) = match what {
1158+
let (render_mode, id, class_html) = match what {
11591159
AssocItemRender::All => {
11601160
write_impl_section_heading(&mut tmp_buf, "Implementations", "implementations");
1161-
(RenderMode::Normal, "implementations-list".to_owned())
1161+
(RenderMode::Normal, "implementations-list".to_owned(), "")
11621162
}
11631163
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
11641164
let id =
@@ -1175,7 +1175,11 @@ fn render_assoc_items_inner(
11751175
),
11761176
&id,
11771177
);
1178-
(RenderMode::ForDeref { mut_: deref_mut_ }, cx.derive_id(id))
1178+
(
1179+
RenderMode::ForDeref { mut_: deref_mut_ },
1180+
cx.derive_id(id),
1181+
r#" class="impl-items""#,
1182+
)
11791183
}
11801184
};
11811185
let mut impls_buf = Buffer::html();
@@ -1199,7 +1203,7 @@ fn render_assoc_items_inner(
11991203
}
12001204
if !impls_buf.is_empty() {
12011205
write!(w, "{}", tmp_buf.into_inner()).unwrap();
1202-
write!(w, "<div id=\"{}\">", id).unwrap();
1206+
write!(w, "<div id=\"{id}\"{class_html}>").unwrap();
12031207
write!(w, "{}", impls_buf.into_inner()).unwrap();
12041208
w.write_str("</div>").unwrap();
12051209
}
@@ -1788,12 +1792,14 @@ fn render_impl(
17881792
.into_string()
17891793
);
17901794
}
1795+
if !default_impl_items.is_empty() || !impl_items.is_empty() {
1796+
w.write_str("<div class=\"impl-items\">");
1797+
close_tags.insert_str(0, "</div>");
1798+
}
17911799
}
17921800
if !default_impl_items.is_empty() || !impl_items.is_empty() {
1793-
w.write_str("<div class=\"impl-items\">");
17941801
w.push_buffer(default_impl_items);
17951802
w.push_buffer(impl_items);
1796-
close_tags.insert_str(0, "</div>");
17971803
}
17981804
w.write_str(&close_tags);
17991805
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#![crate_name="foo"]
2+
3+
use std::ops::{Deref, DerefMut};
4+
5+
// @has foo/struct.Vec.html
6+
// @count - '//h2[@id="deref-methods-Slice"]' 1
7+
// @count - '//div[@id="deref-methods-Slice-1"]' 1
8+
// @count - '//div[@id="deref-methods-Slice-1"][@class="impl-items"]' 1
9+
// @count - '//div[@id="deref-methods-Slice-1"]/div[@class="impl-items"]' 0
10+
pub struct Vec;
11+
12+
pub struct Slice;
13+
14+
impl Deref for Vec {
15+
type Target = Slice;
16+
fn deref(&self) -> &Slice {
17+
&Slice
18+
}
19+
}
20+
21+
impl DerefMut for Vec {
22+
fn deref_mut(&mut self) -> &mut Slice {
23+
&mut Slice
24+
}
25+
}
26+
27+
impl Slice {
28+
pub fn sort_floats(&mut self) {
29+
todo!();
30+
}
31+
}
32+
33+
impl Slice {
34+
pub fn sort(&mut self) {
35+
todo!();
36+
}
37+
}
38+
39+
impl Slice {
40+
pub fn len(&self) {
41+
todo!();
42+
}
43+
}
File renamed without changes.

0 commit comments

Comments
 (0)