Skip to content

Commit 2985b48

Browse files
committed
rustdoc: adjust spacing and typography in header
1 parent b0c2d2e commit 2985b48

23 files changed

+56
-47
lines changed

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2010,9 +2010,9 @@ fn render_rightside(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, render
20102010
);
20112011
if let Some(link) = src_href {
20122012
if has_stability {
2013-
write!(rightside, " · <a class=\"src\" href=\"{link}\">source</a>")
2013+
write!(rightside, " · <a class=\"src\" href=\"{link}\">Source</a>")
20142014
} else {
2015-
write!(rightside, "<a class=\"src rightside\" href=\"{link}\">source</a>")
2015+
write!(rightside, "<a class=\"src rightside\" href=\"{link}\">Source</a>")
20162016
}
20172017
}
20182018
if has_stability && has_src_ref {

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ h1, h2, h3, h4 {
164164
.docblock > h6:first-child {
165165
margin-top: 0;
166166
}
167+
.since, .version {
168+
font-variant-numeric: oldstyle-nums;
169+
}
167170
.main-heading h1 {
168171
margin: 0;
169172
padding: 0;
@@ -185,7 +188,7 @@ h1, h2, h3, h4 {
185188
grid-template-columns: minmax(105px, 1fr) minmax(0, max-content);
186189
grid-template-rows: minmax(25px, min-content) min-content min-content;
187190
padding-bottom: 6px;
188-
margin-bottom: 11px;
191+
margin-bottom: 15px;
189192
}
190193
.rustdoc-breadcrumbs {
191194
grid-area: main-heading-breadcrumbs;
@@ -1004,6 +1007,7 @@ nav.sub {
10041007
display: flex;
10051008
height: 34px;
10061009
flex-grow: 1;
1010+
margin-bottom: 4px;
10071011
}
10081012
.src nav.sub {
10091013
margin: 0 0 -10px 0;
@@ -2253,7 +2257,12 @@ in src-script.js and main.js
22532257

22542258
/* We don't display this button on mobile devices. */
22552259
#copy-path {
2256-
display: none;
2260+
/* display: none; avoided as a layout hack.
2261+
When there's one line, we get an effective line-height of 34px,
2262+
because that's how big the image is, but if the header wraps,
2263+
they're packed more tightly than that. */
2264+
width: 0;
2265+
visibility: hidden;
22572266
}
22582267

22592268
/* Text label takes up too much space at this size. */

src/librustdoc/html/templates/print_item.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1>
2626
{% match src_href %}
2727
{% when Some with (href) %}
2828
{% if !stability_since_raw.is_empty() +%} · {%+ endif %}
29-
<a class="src" href="{{href|safe}}">source</a> {#+ #}
29+
<a class="src" href="{{href|safe}}">Source</a> {#+ #}
3030
{% else %}
3131
{% endmatch %}
3232
</span> {# #}

tests/rustdoc-gui/item-info.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ store-position: (
2020
{"x": second_line_x, "y": second_line_y},
2121
)
2222
assert: |first_line_x| != |second_line_x| && |first_line_x| == 516 && |second_line_x| == 272
23-
assert: |first_line_y| != |second_line_y| && |first_line_y| == 714 && |second_line_y| == 737
23+
assert: |first_line_y| != |second_line_y| && |first_line_y| == 718 && |second_line_y| == 741
2424

2525
// Now we ensure that they're not rendered on the same line.
2626
set-window-size: (1100, 800)

tests/rustdoc-gui/scrape-examples-layout.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ click: ".scraped-example .button-holder .expand"
8080
store-value: (offset_y, 4)
8181

8282
// First with desktop
83-
assert-position: (".scraped-example", {"y": 252})
84-
assert-position: (".scraped-example .prev", {"y": 252 + |offset_y|})
83+
assert-position: (".scraped-example", {"y": 256})
84+
assert-position: (".scraped-example .prev", {"y": 256 + |offset_y|})
8585

8686
// Gradient background should be at the top of the code block.
8787
assert-css: (".scraped-example .example-wrap::before", {"top": "0px"})
@@ -90,8 +90,8 @@ assert-css: (".scraped-example .example-wrap::after", {"bottom": "0px"})
9090
// Then with mobile
9191
set-window-size: (600, 600)
9292
store-size: (".scraped-example .scraped-example-title", {"height": title_height})
93-
assert-position: (".scraped-example", {"y": 287})
94-
assert-position: (".scraped-example .prev", {"y": 287 + |offset_y| + |title_height|})
93+
assert-position: (".scraped-example", {"y": 291})
94+
assert-position: (".scraped-example .prev", {"y": 291 + |offset_y| + |title_height|})
9595

9696
define-function: (
9797
"check_title_and_code_position",

tests/rustdoc-gui/sidebar-source-code-display.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ click: "#sidebar-button"
141141
wait-for-css: (".src .sidebar > *", {"visibility": "hidden"})
142142
// We scroll to line 117 to change the scroll position.
143143
scroll-to: '//*[@id="117"]'
144-
store-value: (y_offset, "2570")
144+
store-value: (y_offset, "2578")
145145
assert-window-property: {"pageYOffset": |y_offset|}
146146
// Expanding the sidebar...
147147
click: "#sidebar-button"

tests/rustdoc-gui/source-anchor-scroll.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ set-window-size: (600, 800)
88
assert-property: ("html", {"scrollTop": "0"})
99

1010
click: '//a[text() = "barbar" and @href="#5-7"]'
11-
assert-property: ("html", {"scrollTop": "200"})
11+
assert-property: ("html", {"scrollTop": "208"})
1212
click: '//a[text() = "bar" and @href="#28-36"]'
13-
assert-property: ("html", {"scrollTop": "231"})
13+
assert-property: ("html", {"scrollTop": "239"})
1414
click: '//a[normalize-space() = "sub_fn" and @href="#2-4"]'
15-
assert-property: ("html", {"scrollTop": "128"})
15+
assert-property: ("html", {"scrollTop": "136"})
1616

1717
// We now check that clicking on lines doesn't change the scroll
1818
// Extra information: the "sub_fn" function header is on line 1.
1919
click: '//*[@id="6"]'
20-
assert-property: ("html", {"scrollTop": "128"})
20+
assert-property: ("html", {"scrollTop": "136"})

tests/rustdoc-gui/source-code-page.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
8989
// do anything (and certainly not add a `#NaN` to the URL!).
9090
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
9191
// We use this assert-position to know where we will click.
92-
assert-position: ("//*[@id='1']", {"x": 88, "y": 163})
92+
assert-position: ("//*[@id='1']", {"x": 88, "y": 171})
9393
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
9494
click: (163, 77)
9595
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
@@ -165,15 +165,15 @@ assert-css: ("nav.sub", {"flex-direction": "row"})
165165
// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form]
166166
assert-position: ("nav.sub form", {"y": 15})
167167
assert-property: ("nav.sub form", {"offsetHeight": 34})
168-
assert-position: ("h1", {"y": 64})
168+
assert-position: ("h1", {"y": 68})
169169
// 15 = 64 - 34 - 15
170170

171171
// Now do the same check on moderately-sized, tablet mobile.
172172
set-window-size: (700, 700)
173173
assert-css: ("nav.sub", {"flex-direction": "row"})
174174
assert-position: ("nav.sub form", {"y": 8})
175175
assert-property: ("nav.sub form", {"offsetHeight": 34})
176-
assert-position: ("h1", {"y": 50})
176+
assert-position: ("h1", {"y": 54})
177177
// 8 = 50 - 34 - 8
178178

179179
// Check the sidebar directory entries have a marker and spacing (tablet).
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedconstant.YOLO" class="method"><a class="src 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>
1+
<section id="associatedconstant.YOLO" class="method"><a class="src 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>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
1+
<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">Source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>
1+
<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>
1+
<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">Source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>
1+
<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">Source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedtype.T" class="method"><a class="src 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>
1+
<section id="associatedtype.T" class="method"><a class="src 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>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
1+
<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">Source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>

tests/rustdoc/assoc-type-source-link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pub struct Bar;
99

1010
impl Bar {
11-
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a' 'source'
11+
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a' 'Source'
1212
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a/@href' \
1313
// '../src/foo/assoc-type-source-link.rs.html#14'
1414
pub type Y = u8;
@@ -19,7 +19,7 @@ pub trait Foo {
1919
}
2020

2121
impl Foo for Bar {
22-
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a' 'source'
22+
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a' 'Source'
2323
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a/@href' \
2424
// '../src/foo/assoc-type-source-link.rs.html#25'
2525
type Z = u8;

tests/rustdoc/ensure-src-link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// This test ensures that the [src] link is present on traits items.
44

5-
//@ has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="src"]' "source"
5+
//@ has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="src"]' "Source"
66
pub use std::iter::Iterator;

tests/rustdoc/external-macro-src.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#[macro_use]
66
extern crate external_macro_src;
77

8-
//@ has foo/index.html '//a[@href="../src/foo/external-macro-src.rs.html#3-12"]' 'source'
8+
//@ has foo/index.html '//a[@href="../src/foo/external-macro-src.rs.html#3-12"]' 'Source'
99

1010
//@ has foo/struct.Foo.html
11-
//@ has - '//a[@href="../src/foo/external-macro-src.rs.html#12"]' 'source'
11+
//@ has - '//a[@href="../src/foo/external-macro-src.rs.html#12"]' 'Source'
1212
make_foo!();

tests/rustdoc/source-version-separator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
#![feature(staged_api)]
44

55
//@ has foo/trait.Bar.html
6-
//@ has - '//div[@class="main-heading"]/*[@class="sub-heading"]' '1.0.0 · source'
6+
//@ has - '//div[@class="main-heading"]/*[@class="sub-heading"]' '1.0.0 · Source'
77
#[stable(feature = "bar", since = "1.0")]
88
pub trait Bar {
9-
//@ has - '//*[@id="tymethod.foo"]/*[@class="rightside"]' '3.0.0 · source'
9+
//@ has - '//*[@id="tymethod.foo"]/*[@class="rightside"]' '3.0.0 · Source'
1010
#[stable(feature = "foobar", since = "3.0")]
1111
fn foo();
1212
}
1313

14-
//@ has - '//div[@id="implementors-list"]//*[@class="rightside"]' '4.0.0 · source'
14+
//@ has - '//div[@id="implementors-list"]//*[@class="rightside"]' '4.0.0 · Source'
1515

1616
//@ has foo/struct.Foo.html
17-
//@ has - '//div[@class="main-heading"]/*[@class="sub-heading"]' '1.0.0 · source'
17+
//@ has - '//div[@class="main-heading"]/*[@class="sub-heading"]' '1.0.0 · Source'
1818
#[stable(feature = "baz", since = "1.0")]
1919
pub struct Foo;
2020

2121
impl Foo {
22-
//@ has - '//*[@id="method.foofoo"]/*[@class="rightside"]' '3.0.0 · source'
22+
//@ has - '//*[@id="method.foofoo"]/*[@class="rightside"]' '3.0.0 · Source'
2323
#[stable(feature = "foobar", since = "3.0")]
2424
pub fn foofoo() {}
2525
}

tests/rustdoc/src-link-external-macro-26606.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
extern crate issue_26606_macro;
1111

1212
//@ has issue_26606/constant.FOO.html
13-
//@ has - '//a[@href="../src/issue_26606/src-link-external-macro-26606.rs.html#14"]' 'source'
13+
//@ has - '//a[@href="../src/issue_26606/src-link-external-macro-26606.rs.html#14"]' 'Source'
1414
make_item!(FOO);

tests/rustdoc/src-links-auto-impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
//@ has foo/struct.Unsized.html
44
//@ has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header"]' 'impl !Sized for Unsized'
5-
//@ !has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="src"]' 'source'
5+
//@ !has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="src"]' 'Source'
66
//@ has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header"]' 'impl Sync for Unsized'
7-
//@ !has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="src"]' 'source'
7+
//@ !has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="src"]' 'Source'
88
//@ has - '//*[@id="impl-Any-for-T"]/h3[@class="code-header"]' 'impl<T> Any for T'
9-
//@ has - '//*[@id="impl-Any-for-T"]//a[@class="src rightside"]' 'source'
9+
//@ has - '//*[@id="impl-Any-for-T"]//a[@class="src rightside"]' 'Source'
1010
pub struct Unsized {
1111
data: [u8],
1212
}

tests/rustdoc/thread-local-src.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_name = "foo"]
22

3-
//@ has foo/index.html '//a[@href="../src/foo/thread-local-src.rs.html#1-6"]' 'source'
3+
//@ has foo/index.html '//a[@href="../src/foo/thread-local-src.rs.html#1-6"]' 'Source'
44

5-
//@ has foo/constant.FOO.html '//a[@href="../src/foo/thread-local-src.rs.html#6"]' 'source'
5+
//@ has foo/constant.FOO.html '//a[@href="../src/foo/thread-local-src.rs.html#6"]' 'Source'
66
thread_local!(pub static FOO: bool = false);

tests/rustdoc/trait-src-link.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#![crate_name = "quix"]
22
pub trait Foo {
3-
//@ has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' 'source'
3+
//@ has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' 'Source'
44
fn required();
55

6-
//@ has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'source'
6+
//@ has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'Source'
77
fn provided() {}
88
}
99

1010
pub struct Bar;
1111

1212
impl Foo for Bar {
13-
//@ has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' 'source'
13+
//@ has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' 'Source'
1414
fn required() {}
15-
//@ has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'source'
15+
//@ has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' 'Source'
1616
}
1717

1818
pub struct Baz;
1919

2020
impl Foo for Baz {
21-
//@ has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' 'source'
21+
//@ has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' 'Source'
2222
fn required() {}
2323

24-
//@ has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' 'source'
24+
//@ has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' 'Source'
2525
fn provided() {}
2626
}

0 commit comments

Comments
 (0)