Skip to content

Commit 7a51adf

Browse files
committed
Allow source link to wrap onto next line
Like the out-of-band information at the top of the page, this uses flex-wrap: wrap to allow `source` to move to the next line when space is tight. Also, on mobile layouts move it to the next line always, for a more consistent interface. This allows more of the method signature to be displayed on a single line, and avoids confusing `source` with one of the items in the method signature. Also tweak the padding on summary items slightly so they line up properly with their docblock.
1 parent bb8c2f4 commit 7a51adf

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

src/librustdoc/html/render/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ fn render_impl(
14031403
"<section id=\"{}\" class=\"{}{} has-srclink\">",
14041404
id, item_type, in_trait_class,
14051405
);
1406-
render_rightside(w, cx, item, containing_item, render_mode);
14071406
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14081407
w.write_str("<h4 class=\"code-header\">");
14091408
render_assoc_item(
@@ -1415,6 +1414,7 @@ fn render_impl(
14151414
render_mode,
14161415
);
14171416
w.write_str("</h4>");
1417+
render_rightside(w, cx, item, containing_item, render_mode);
14181418
w.write_str("</section>");
14191419
}
14201420
}
@@ -1426,7 +1426,6 @@ fn render_impl(
14261426
"<section id=\"{}\" class=\"{}{} has-srclink\">",
14271427
id, item_type, in_trait_class
14281428
);
1429-
render_rightside(w, cx, item, containing_item, render_mode);
14301429
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14311430
w.write_str("<h4 class=\"code-header\">");
14321431
assoc_const(
@@ -1443,6 +1442,7 @@ fn render_impl(
14431442
cx,
14441443
);
14451444
w.write_str("</h4>");
1445+
render_rightside(w, cx, item, containing_item, render_mode);
14461446
w.write_str("</section>");
14471447
}
14481448
clean::TyAssocTypeItem(generics, bounds) => {
@@ -1698,7 +1698,6 @@ pub(crate) fn render_impl_summary(
16981698
format!(" data-aliases=\"{}\"", aliases.join(","))
16991699
};
17001700
write!(w, "<section id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
1701-
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
17021701
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
17031702
write!(w, "<h3 class=\"code-header in-band\">");
17041703

@@ -1726,15 +1725,16 @@ pub(crate) fn render_impl_summary(
17261725
write!(w, "{}", i.inner_impl().print(false, cx));
17271726
}
17281727
write!(w, "</h3>");
1728+
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
1729+
1730+
w.write_str("</section>");
17291731

17301732
let is_trait = i.inner_impl().trait_.is_some();
17311733
if is_trait {
17321734
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
17331735
write!(w, "<span class=\"item-info\">{}</span>", portability);
17341736
}
17351737
}
1736-
1737-
w.write_str("</section>");
17381738
}
17391739

17401740
fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {

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

+10-19
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ h4.code-header {
173173
border-bottom-style: none;
174174
margin: 0;
175175
padding: 0;
176-
margin-top: 0.6em;
177-
margin-bottom: 0.4em;
178176
}
179177
.impl,
180178
.impl-items .method,
@@ -621,7 +619,6 @@ h2.location a {
621619
}
622620

623621
.method > .code-header, .trait-impl > .code-header {
624-
max-width: calc(100% - 41px);
625622
display: block;
626623
}
627624

@@ -1083,20 +1080,19 @@ body.blur > :not(#help) {
10831080
font-size: initial;
10841081
}
10851082

1086-
.rightside {
1087-
padding-left: 12px;
1088-
padding-right: 2px;
1089-
position: initial;
1090-
}
1091-
10921083
.impl-items .srclink, .impl .srclink, .methods .srclink {
10931084
/* Override header settings otherwise it's too bold */
10941085
font-weight: normal;
10951086
font-size: 1rem;
10961087
}
10971088

1098-
.rightside {
1099-
float: right;
1089+
.has-srclink {
1090+
display: flex;
1091+
flex-wrap: wrap;
1092+
font-size: 1rem;
1093+
margin-bottom: 0.75rem;
1094+
/* Push the src link out to the right edge consistently */
1095+
justify-content: space-between;
11001096
}
11011097

11021098
.variants_table {
@@ -1713,7 +1709,8 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17131709
}
17141710

17151711
.rustdoc,
1716-
.main-heading {
1712+
.main-heading,
1713+
.has-srclink {
17171714
flex-direction: column;
17181715
}
17191716

@@ -1854,12 +1851,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18541851
display: none !important;
18551852
}
18561853

1857-
.notable-traits {
1858-
position: absolute;
1859-
left: -22px;
1860-
top: 24px;
1861-
}
1862-
18631854
#titles > button > div.count {
18641855
float: left;
18651856
width: 100%;
@@ -1959,7 +1950,7 @@ details.rustdoc-toggle[open] > summary.hideme::after {
19591950

19601951
/* Position of the "[-]" element. */
19611952
details.rustdoc-toggle:not(.top-doc) > summary {
1962-
margin-left: 10px;
1953+
margin-left: 12px;
19631954
}
19641955
.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before,
19651956
#main-content > details.rustdoc-toggle:not(.top-doc) > summary::before,

src/test/rustdoc-gui/duplicate-macro-reexport.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test ensures that there is no macro duplicates in the sidebar.
22
goto: file://|DOC_PATH|/test_docs/macro.a.html
33
// Waiting for the elements in the sidebar to be rendered.
4-
wait-for: ".sidebar-elems .others .macro"
4+
wait-for: ".sidebar-elems .macro"
55
// Check there is only one macro named "a" listed in the sidebar.
66
assert-count: (
77
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']",

src/test/rustdoc-gui/toggle-click-deadspace.goml

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ goto: file://|DOC_PATH|/lib2/struct.Foo.html
44
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
55
click: "h4.code-header" // This is the position of "pub" in "pub fn a_method"
66
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
7-
click: ".impl-items .rustdoc-toggle summary::before" // This is the position of "[-]" next to that pub fn.
8-
assert-attribute-false: (".impl-items .rustdoc-toggle", {"open": ""})
97

108
// Click the "Trait" part of "impl Trait" and verify it navigates.
119
click: "#impl-Trait h3 a:first-of-type"

0 commit comments

Comments
 (0)