Skip to content

Commit 2fadfe0

Browse files
authored
Rollup merge of #102521 - notriddle:notriddle/impl-items-section, r=GuillaumeGomez
rustdoc: add missing margin to no-docblock methods Fixes another regression caused by 8846c08, this time fixing the appearance of methods that have no docblock (we didn't notice this one because libstd docs *always* have docblocks). See how it looks at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/enum.Type.html#implementations <details> # Before ![image](https://user-images.githubusercontent.com/1593513/193318777-2bc082fb-6579-4bd8-a0e3-d23a32b4820f.png) # After ![image](https://user-images.githubusercontent.com/1593513/193318968-b6ccacad-940b-4ed3-a0ae-dcf2079c2bae.png) </details> See how it looks at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/trait.AttributesExt.html <details> # Before ![image](https://user-images.githubusercontent.com/1593513/193319636-7ff9c99e-0208-462c-99de-7672e92ce4d6.png) # After ![image](https://user-images.githubusercontent.com/1593513/193322675-403bd165-7394-43e2-8ab4-d1f364666093.png) </details>
2 parents eaf1c7a + 8308c4b commit 2fadfe0

10 files changed

+37
-14
lines changed

src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
718718
if toggled {
719719
write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>");
720720
}
721-
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
721+
write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id);
722722
render_rightside(w, cx, m, t, RenderMode::Normal);
723723
write!(w, "<h4 class=\"code-header\">");
724724
render_assoc_item(
@@ -730,7 +730,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
730730
RenderMode::Normal,
731731
);
732732
w.write_str("</h4>");
733-
w.write_str("</div>");
733+
w.write_str("</section>");
734734
if toggled {
735735
write!(w, "</summary>");
736736
w.push_buffer(content);

src/librustdoc/html/static/css/rustdoc.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,10 @@ in storage.js plus the media query with (min-width: 701px)
20062006
.method-toggle summary,
20072007
.implementors-toggle summary,
20082008
.impl,
2009-
#implementors-list > .docblock {
2009+
#implementors-list > .docblock,
2010+
.impl-items > section,
2011+
.methods > section
2012+
{
20102013
margin-bottom: 0.75em;
20112014
}
20122015

src/test/rustdoc-gui/no-docblock.goml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This test checks that there are margins applied to methods with no docblocks.
2+
goto: file://|DOC_PATH|/test_docs/trait.TraitWithNoDocblocks.html
3+
// Check that the two methods are more than 24px apart.
4+
compare-elements-position-near-false: ("//*[@id='tymethod.first_fn']", "//*[@id='tymethod.second_fn']", {"y": 24})
5+
6+
goto: file://|DOC_PATH|/test_docs/struct.TypeWithNoDocblocks.html
7+
// Check that the two methods are more than 24px apart.
8+
compare-elements-position-near-false: ("//*[@id='method.first_fn']", "//*[@id='method.second_fn']", {"y": 24})

src/test/rustdoc-gui/sidebar-mobile-scroll.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
66

77
// Scroll down.
88
scroll-to: "//h2[@id='blanket-implementations']"
9-
assert-window-property: {"pageYOffset": "639"}
9+
assert-window-property: {"pageYOffset": "651"}
1010

1111
// Open the sidebar menu.
1212
click: ".sidebar-menu-toggle"
@@ -21,11 +21,11 @@ assert-window-property: {"pageYOffset": "0"}
2121
// Close the sidebar menu. Make sure the scroll position gets restored.
2222
click: ".sidebar-menu-toggle"
2323
wait-for-css: (".sidebar", {"left": "-1000px"})
24-
assert-window-property: {"pageYOffset": "639"}
24+
assert-window-property: {"pageYOffset": "651"}
2525

2626
// Now test that scrollability returns when the browser window is just resized.
2727
click: ".sidebar-menu-toggle"
2828
wait-for-css: (".sidebar", {"left": "0px"})
2929
assert-window-property: {"pageYOffset": "0"}
3030
size: (900, 600)
31-
assert-window-property: {"pageYOffset": "639"}
31+
assert-window-property: {"pageYOffset": "651"}

src/test/rustdoc-gui/src/test_docs/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,15 @@ impl<R: std::io::Read> std::iter::Iterator for NotableStructWithLongName<R> {
355355

356356
fn next(&mut self) -> Option<Self::Item> { () }
357357
}
358+
359+
pub trait TraitWithNoDocblocks {
360+
fn first_fn(&self);
361+
fn second_fn(&self);
362+
}
363+
364+
pub struct TypeWithNoDocblocks;
365+
366+
impl TypeWithNoDocblocks {
367+
pub fn first_fn(&self) {}
368+
pub fn second_fn(&self) {}
369+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></div>
1+
<section id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></div>
1+
<section id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></section>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></div>
1+
<section id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></section>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></div>
1+
<section id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section>

src/test/rustdoc/rfc-2632-const-trait-impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub struct S<T>(T);
1818
// @has - '//pre[@class="rust trait"]/code/span[@class="where"]' ': Clone'
1919
#[const_trait]
2020
pub trait Tr<T> {
21-
// @!has - '//div[@id="method.a"]/h4[@class="code-header"]' '~const'
22-
// @has - '//div[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
23-
// @!has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
24-
// @has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
21+
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]' '~const'
22+
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
23+
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
24+
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
2525
fn a<A: ~const Clone + ~const Destruct>()
2626
where
2727
Option<A>: ~const Clone + ~const Destruct,

0 commit comments

Comments
 (0)