diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 7e17f09aecdcb..beaa6497b8caa 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -2086,6 +2086,7 @@ fn render_impl(
.split_summary_and_content()
})
.unwrap_or((None, None));
+
write!(
w,
"{}",
@@ -2097,24 +2098,19 @@ fn render_impl(
use_absolute,
aliases,
before_dox.as_deref(),
+ trait_.is_none() && impl_.items.is_empty(),
)
)?;
if toggled {
w.write_str("")?;
}
- if before_dox.is_some() {
- if trait_.is_none() && impl_.items.is_empty() {
- w.write_str(
- "
\
-
This impl block contains no items.
\
-
",
- )?;
- }
- if let Some(after_dox) = after_dox {
- write!(w, "{after_dox}
")?;
- }
+ if before_dox.is_some()
+ && let Some(after_dox) = after_dox
+ {
+ write!(w, "{after_dox}
")?;
}
+
if !default_impl_items.is_empty() || !impl_items.is_empty() {
w.write_str("")?;
close_tags.push("
");
@@ -2182,6 +2178,7 @@ fn render_impl_summary(
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
aliases: &[String],
doc: Option<&str>,
+ impl_is_empty: bool,
) -> impl fmt::Display {
fmt::from_fn(move |w| {
let inner_impl = i.inner_impl();
@@ -2237,6 +2234,13 @@ fn render_impl_summary(
}
if let Some(doc) = doc {
+ if impl_is_empty {
+ w.write_str(
+ "\
+
This impl block contains no items.
\
+
",
+ )?;
+ }
write!(w, "{doc}
")?;
}
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index a6dd06b76ea97..19ac24a5d6e3d 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -2319,7 +2319,10 @@ details.toggle > summary:not(.hideme)::before {
doc block while aligning it with the impl block items. */
.implementors-toggle > .docblock,
/* We indent trait items as well. */
-#main-content > .methods > :not(.item-info) {
+#main-content > .methods > :not(.item-info),
+.impl > .item-info,
+.impl > .docblock,
+.impl + .docblock {
margin-left: var(--impl-items-indent);
}
diff --git a/tests/rustdoc-gui/docblock-table-overflow.goml b/tests/rustdoc-gui/docblock-table-overflow.goml
index 18e5b4d7f3590..e603c3a4d22e0 100644
--- a/tests/rustdoc-gui/docblock-table-overflow.goml
+++ b/tests/rustdoc-gui/docblock-table-overflow.goml
@@ -11,7 +11,7 @@ assert-property: (".top-doc .docblock table", {"scrollWidth": "1572"})
// Checking it works on other doc blocks as well...
// Logically, the ".docblock" and the "" should have the same scroll width (if we exclude the margin).
-assert-property: ("#implementations-list > details .docblock", {"scrollWidth": 816})
+assert-property: ("#implementations-list > details .docblock", {"scrollWidth": 835})
assert-property: ("#implementations-list > details .docblock > p", {"scrollWidth": 835})
// However, since there is overflow in the
, its scroll width is bigger.
assert-property: ("#implementations-list > details .docblock table", {"scrollWidth": "1572"})
diff --git a/tests/rustdoc-gui/impl-doc-indent.goml b/tests/rustdoc-gui/impl-doc-indent.goml
new file mode 100644
index 0000000000000..d647fec6d732d
--- /dev/null
+++ b/tests/rustdoc-gui/impl-doc-indent.goml
@@ -0,0 +1,16 @@
+// Checks the impl block docs have the correct indent.
+go-to: "file://" + |DOC_PATH| + "/test_docs/impls_indent/struct.Context.html"
+
+// First we ensure that the impl items are indent (more on the right of the screen) than the
+// impl itself.
+store-position: ("#impl-Context", {"x": impl_x})
+store-position: ("#impl-Context > .item-info", {"x": impl_item_x})
+assert: |impl_x| < |impl_item_x|
+
+// And we ensure that all impl items have the same indent.
+assert-position: ("#impl-Context > .docblock", {"x": |impl_item_x|})
+assert-position: ("#impl-Context + .docblock", {"x": |impl_item_x|})
+
+// Same with the collapsible impl block.
+assert-position: ("#impl-Context-1 > .docblock", {"x": |impl_item_x|})
+assert-position: (".implementors-toggle > summary + .docblock", {"x": |impl_item_x|})
diff --git a/tests/rustdoc-gui/item-info-overflow.goml b/tests/rustdoc-gui/item-info-overflow.goml
index c325beb6d0669..2c4e06e297c7d 100644
--- a/tests/rustdoc-gui/item-info-overflow.goml
+++ b/tests/rustdoc-gui/item-info-overflow.goml
@@ -21,7 +21,7 @@ compare-elements-property: (
)
assert-property: (
"#impl-SimpleTrait-for-LongItemInfo2 .item-info",
- {"scrollWidth": "916"},
+ {"scrollWidth": "935"},
)
// Just to be sure we're comparing the correct "item-info":
assert-text: (
diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs
index 31f6b7f09b7d0..bb0015b8f9c43 100644
--- a/tests/rustdoc-gui/src/test_docs/lib.rs
+++ b/tests/rustdoc-gui/src/test_docs/lib.rs
@@ -740,3 +740,29 @@ pub mod SidebarSort {
impl Sort for Cell {}
impl<'a> Sort for &'a str {}
}
+
+pub mod impls_indent {
+ pub struct Context;
+
+ /// Working with objects.
+ ///
+ /// # Safety
+ ///
+ /// Functions that take indices of locals do not check bounds on these indices;
+ /// the caller must ensure that the indices are less than the number of locals
+ /// in the current stack frame.
+ impl Context {
+ }
+
+ /// Working with objects.
+ ///
+ /// # Safety
+ ///
+ /// Functions that take indices of locals do not check bounds on these indices;
+ /// the caller must ensure that the indices are less than the number of locals
+ /// in the current stack frame.
+ impl Context {
+ /// bla
+ pub fn bar() {}
+ }
+}