about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-29 15:51:17 +0200
committerGitHub <noreply@github.com>2023-04-29 15:51:17 +0200
commit39ed894926c4e1bc40667e54175d405ad8c4e41c (patch)
tree9b8aed083f6a30f8596d3e50144c1365c30724e0 /src
parentcdcec39be6ceaf1e196ca1d6e7033744832b4f75 (diff)
parent2299ba1ca2afdf56000017c70572ed181e174c37 (diff)
downloadrust-39ed894926c4e1bc40667e54175d405ad8c4e41c.tar.gz
rust-39ed894926c4e1bc40667e54175d405ad8c4e41c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render/mod.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index a5f08fdac11..d90d0aecb93 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1155,10 +1155,10 @@ fn render_assoc_items_inner(
     let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
     if !non_trait.is_empty() {
         let mut tmp_buf = Buffer::html();
-        let (render_mode, id) = match what {
+        let (render_mode, id, class_html) = match what {
             AssocItemRender::All => {
                 write_impl_section_heading(&mut tmp_buf, "Implementations", "implementations");
-                (RenderMode::Normal, "implementations-list".to_owned())
+                (RenderMode::Normal, "implementations-list".to_owned(), "")
             }
             AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
                 let id =
@@ -1175,7 +1175,11 @@ fn render_assoc_items_inner(
                     ),
                     &id,
                 );
-                (RenderMode::ForDeref { mut_: deref_mut_ }, cx.derive_id(id))
+                (
+                    RenderMode::ForDeref { mut_: deref_mut_ },
+                    cx.derive_id(id),
+                    r#" class="impl-items""#,
+                )
             }
         };
         let mut impls_buf = Buffer::html();
@@ -1199,7 +1203,7 @@ fn render_assoc_items_inner(
         }
         if !impls_buf.is_empty() {
             write!(w, "{}", tmp_buf.into_inner()).unwrap();
-            write!(w, "<div id=\"{}\">", id).unwrap();
+            write!(w, "<div id=\"{id}\"{class_html}>").unwrap();
             write!(w, "{}", impls_buf.into_inner()).unwrap();
             w.write_str("</div>").unwrap();
         }
@@ -1788,12 +1792,14 @@ fn render_impl(
                 .into_string()
             );
         }
+        if !default_impl_items.is_empty() || !impl_items.is_empty() {
+            w.write_str("<div class=\"impl-items\">");
+            close_tags.insert_str(0, "</div>");
+        }
     }
     if !default_impl_items.is_empty() || !impl_items.is_empty() {
-        w.write_str("<div class=\"impl-items\">");
         w.push_buffer(default_impl_items);
         w.push_buffer(impl_items);
-        close_tags.insert_str(0, "</div>");
     }
     w.write_str(&close_tags);
 }