From 10c77b1cd0027926a966620c988a3af8643314f2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 28 Apr 2023 12:54:26 -0700 Subject: [PATCH 1/2] rustdoc: move deref tests into a directory --- tests/rustdoc/{ => deref}/deref-const-fn.rs | 0 tests/rustdoc/{ => deref}/deref-mut-methods.rs | 0 tests/rustdoc/{ => deref}/deref-recursive-pathbuf.rs | 0 tests/rustdoc/{ => deref}/deref-recursive.rs | 0 tests/rustdoc/{ => deref}/deref-slice-core.rs | 0 tests/rustdoc/{ => deref}/deref-to-primitive.rs | 0 tests/rustdoc/{ => deref}/deref-typedef.rs | 0 tests/rustdoc/{ => deref}/escape-deref-methods.rs | 0 tests/rustdoc/{ => deref}/issue-100679-sidebar-links-deref.rs | 0 tests/rustdoc/{ => deref}/recursive-deref-sidebar.rs | 0 tests/rustdoc/{ => deref}/recursive-deref.rs | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename tests/rustdoc/{ => deref}/deref-const-fn.rs (100%) rename tests/rustdoc/{ => deref}/deref-mut-methods.rs (100%) rename tests/rustdoc/{ => deref}/deref-recursive-pathbuf.rs (100%) rename tests/rustdoc/{ => deref}/deref-recursive.rs (100%) rename tests/rustdoc/{ => deref}/deref-slice-core.rs (100%) rename tests/rustdoc/{ => deref}/deref-to-primitive.rs (100%) rename tests/rustdoc/{ => deref}/deref-typedef.rs (100%) rename tests/rustdoc/{ => deref}/escape-deref-methods.rs (100%) rename tests/rustdoc/{ => deref}/issue-100679-sidebar-links-deref.rs (100%) rename tests/rustdoc/{ => deref}/recursive-deref-sidebar.rs (100%) rename tests/rustdoc/{ => deref}/recursive-deref.rs (100%) diff --git a/tests/rustdoc/deref-const-fn.rs b/tests/rustdoc/deref/deref-const-fn.rs similarity index 100% rename from tests/rustdoc/deref-const-fn.rs rename to tests/rustdoc/deref/deref-const-fn.rs diff --git a/tests/rustdoc/deref-mut-methods.rs b/tests/rustdoc/deref/deref-mut-methods.rs similarity index 100% rename from tests/rustdoc/deref-mut-methods.rs rename to tests/rustdoc/deref/deref-mut-methods.rs diff --git a/tests/rustdoc/deref-recursive-pathbuf.rs b/tests/rustdoc/deref/deref-recursive-pathbuf.rs similarity index 100% rename from tests/rustdoc/deref-recursive-pathbuf.rs rename to tests/rustdoc/deref/deref-recursive-pathbuf.rs diff --git a/tests/rustdoc/deref-recursive.rs b/tests/rustdoc/deref/deref-recursive.rs similarity index 100% rename from tests/rustdoc/deref-recursive.rs rename to tests/rustdoc/deref/deref-recursive.rs diff --git a/tests/rustdoc/deref-slice-core.rs b/tests/rustdoc/deref/deref-slice-core.rs similarity index 100% rename from tests/rustdoc/deref-slice-core.rs rename to tests/rustdoc/deref/deref-slice-core.rs diff --git a/tests/rustdoc/deref-to-primitive.rs b/tests/rustdoc/deref/deref-to-primitive.rs similarity index 100% rename from tests/rustdoc/deref-to-primitive.rs rename to tests/rustdoc/deref/deref-to-primitive.rs diff --git a/tests/rustdoc/deref-typedef.rs b/tests/rustdoc/deref/deref-typedef.rs similarity index 100% rename from tests/rustdoc/deref-typedef.rs rename to tests/rustdoc/deref/deref-typedef.rs diff --git a/tests/rustdoc/escape-deref-methods.rs b/tests/rustdoc/deref/escape-deref-methods.rs similarity index 100% rename from tests/rustdoc/escape-deref-methods.rs rename to tests/rustdoc/deref/escape-deref-methods.rs diff --git a/tests/rustdoc/issue-100679-sidebar-links-deref.rs b/tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs similarity index 100% rename from tests/rustdoc/issue-100679-sidebar-links-deref.rs rename to tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs diff --git a/tests/rustdoc/recursive-deref-sidebar.rs b/tests/rustdoc/deref/recursive-deref-sidebar.rs similarity index 100% rename from tests/rustdoc/recursive-deref-sidebar.rs rename to tests/rustdoc/deref/recursive-deref-sidebar.rs diff --git a/tests/rustdoc/recursive-deref.rs b/tests/rustdoc/deref/recursive-deref.rs similarity index 100% rename from tests/rustdoc/recursive-deref.rs rename to tests/rustdoc/deref/recursive-deref.rs From 2299ba1ca2afdf56000017c70572ed181e174c37 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 28 Apr 2023 13:10:25 -0700 Subject: [PATCH 2/2] rustdoc: fix weird margins between Deref impl items 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. --- src/librustdoc/html/render/mod.rs | 18 +++++--- .../deref/deref-multiple-impl-blocks.rs | 43 +++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/rustdoc/deref/deref-multiple-impl-blocks.rs diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a5f08fdac11c9..d90d0aecb93ad 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, "
", id).unwrap(); + write!(w, "
").unwrap(); write!(w, "{}", impls_buf.into_inner()).unwrap(); w.write_str("
").unwrap(); } @@ -1788,12 +1792,14 @@ fn render_impl( .into_string() ); } + if !default_impl_items.is_empty() || !impl_items.is_empty() { + w.write_str("
"); + close_tags.insert_str(0, "
"); + } } if !default_impl_items.is_empty() || !impl_items.is_empty() { - w.write_str("
"); w.push_buffer(default_impl_items); w.push_buffer(impl_items); - close_tags.insert_str(0, "
"); } w.write_str(&close_tags); } diff --git a/tests/rustdoc/deref/deref-multiple-impl-blocks.rs b/tests/rustdoc/deref/deref-multiple-impl-blocks.rs new file mode 100644 index 0000000000000..fa3607c5fc12d --- /dev/null +++ b/tests/rustdoc/deref/deref-multiple-impl-blocks.rs @@ -0,0 +1,43 @@ +#![crate_name="foo"] + +use std::ops::{Deref, DerefMut}; + +// @has foo/struct.Vec.html +// @count - '//h2[@id="deref-methods-Slice"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"][@class="impl-items"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"]/div[@class="impl-items"]' 0 +pub struct Vec; + +pub struct Slice; + +impl Deref for Vec { + type Target = Slice; + fn deref(&self) -> &Slice { + &Slice + } +} + +impl DerefMut for Vec { + fn deref_mut(&mut self) -> &mut Slice { + &mut Slice + } +} + +impl Slice { + pub fn sort_floats(&mut self) { + todo!(); + } +} + +impl Slice { + pub fn sort(&mut self) { + todo!(); + } +} + +impl Slice { + pub fn len(&self) { + todo!(); + } +}