Skip to content

rustdoc: fix weird margins between Deref impl items #110964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions tests/rustdoc/deref/deref-multiple-impl-blocks.rs
Original file line number Diff line number Diff line change
@@ -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!();
}
}
File renamed without changes.