Skip to content

Commit 962c0a4

Browse files
committed
Make source links look cleaner
Change from syntaxy-looking [src] to the plain word "source".
1 parent a77cc64 commit 962c0a4

20 files changed

+96
-79
lines changed

library/std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
//! development you may want to press the `[-]` button near the top of the
3636
//! page to collapse it into a more skimmable view.
3737
//!
38-
//! While you are looking at that `[-]` button also notice the `[src]`
39-
//! button. Rust's API documentation comes with the source code and you are
38+
//! While you are looking at that `[-]` button also notice the `source`
39+
//! link. Rust's API documentation comes with the source code and you are
4040
//! encouraged to read it. The standard library source is generally high
4141
//! quality and a peek behind the curtains is often enlightening.
4242
//!

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ crate struct Context<'tcx> {
6565
///
6666
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
6767
crate shared: Rc<SharedContext<'tcx>>,
68-
/// This flag indicates whether `[src]` links should be generated or not. If
68+
/// This flag indicates whether source links should be generated or not. If
6969
/// the source files are present in the html rendering, then this will be
7070
/// `true`.
7171
crate include_sources: bool,

src/librustdoc/html/render/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl StylePath {
182182

183183
fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
184184
if let Some(l) = cx.src_href(item) {
185-
write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">[src]</a>", l)
185+
write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">source</a>", l)
186186
}
187187
}
188188

@@ -807,7 +807,7 @@ fn render_stability_since_raw(
807807
const_stability: Option<ConstStability>,
808808
containing_ver: Option<Symbol>,
809809
containing_const_ver: Option<Symbol>,
810-
) {
810+
) -> bool {
811811
let ver = ver.filter(|inner| !inner.is_empty());
812812

813813
match (ver, const_stability) {
@@ -850,8 +850,9 @@ fn render_stability_since_raw(
850850
v
851851
);
852852
}
853-
_ => {}
853+
_ => return false,
854854
}
855+
true
855856
}
856857

857858
fn render_assoc_item(
@@ -1640,7 +1641,7 @@ fn render_impl(
16401641
}
16411642

16421643
// Render the items that appear on the right side of methods, impls, and
1643-
// associated types. For example "1.0.0 (const: 1.39.0) [src]".
1644+
// associated types. For example "1.0.0 (const: 1.39.0) · source".
16441645
fn render_rightside(
16451646
w: &mut Buffer,
16461647
cx: &Context<'_>,
@@ -1658,13 +1659,16 @@ fn render_rightside(
16581659
};
16591660

16601661
write!(w, "<div class=\"rightside\">");
1661-
render_stability_since_raw(
1662+
let has_stability = render_stability_since_raw(
16621663
w,
16631664
item.stable_since(tcx),
16641665
const_stability,
16651666
containing_item.stable_since(tcx),
16661667
const_stable_since,
16671668
);
1669+
if has_stability {
1670+
w.write_str(" · ");
1671+
}
16681672

16691673
write_srclink(cx, item, w);
16701674
w.write_str("</div>");

src/librustdoc/html/render/print_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub(super) fn print_item(
108108
);
109109
let stability_since_raw: String = stability_since_raw.into_inner();
110110

111-
// Write `src` tag
111+
// Write source tag
112112
//
113113
// When this item is part of a `crate use` in a downstream crate, the
114-
// [src] link in the downstream documentation will actually come back to
114+
// source link in the downstream documentation will actually come back to
115115
// this page, and this link will be auto-clicked. The `id` attribute is
116116
// used to find the link to auto-click.
117117
let src_href =
@@ -1467,7 +1467,7 @@ fn render_stability_since(
14671467
item.const_stability(tcx),
14681468
containing_item.stable_since(tcx),
14691469
containing_item.const_stable_since(tcx),
1470-
)
1470+
);
14711471
}
14721472

14731473
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {

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

+20-12
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,25 @@ h1, h2, h3, h4 {
137137
margin: 15px 0 5px 0;
138138
}
139139
h1.fqn {
140+
margin: 0;
141+
padding: 0;
142+
}
143+
.main-heading {
140144
display: flex;
141-
border-bottom: 1px dashed;
142-
margin-top: 0;
145+
border-bottom: 1px dashed #DDDDDD;
146+
padding-bottom: 6px;
147+
margin-bottom: 15px;
143148

144149
/* workaround to keep flex from breaking below 700 px width due to the float: right on the nav
145150
above the h1 */
146151
padding-left: 1px;
147152
}
148-
h1.fqn > .in-band > a:hover {
153+
.main-heading a:hover {
149154
text-decoration: underline;
150155
}
156+
#toggle-all-docs {
157+
text-decoration: none;
158+
}
151159
/* The only headings that get underlines are:
152160
Markdown-generated headings within the top-doc
153161
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)
@@ -195,11 +203,13 @@ h1, h2, h3, h4, h5, h6,
195203
.sidebar, a.source, .search-input, .search-results .result-name,
196204
.content table td:first-child > a,
197205
.item-left > a,
198-
div.item-list .out-of-band, span.since,
206+
.out-of-band,
207+
span.since,
199208
#source-sidebar, #sidebar-toggle,
200209
details.rustdoc-toggle > summary::before,
201210
div.impl-items > div:not(.docblock):not(.item-info),
202-
.content ul.crate a.crate, a.srclink,
211+
.content ul.crate a.crate,
212+
a.srclink,
203213
/* This selector is for the items listed in the "all items" page. */
204214
#main-content > ul.docblock > li > a {
205215
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@@ -605,10 +615,12 @@ nav.sub {
605615
.content .out-of-band {
606616
flex-grow: 0;
607617
text-align: right;
608-
font-size: 1.4375rem;
609-
margin: 0px;
618+
margin-left: auto;
619+
margin-right: 0;
620+
font-size: 1.15rem;
610621
padding: 0 0 0 12px;
611622
font-weight: normal;
623+
float: right;
612624
}
613625

614626
.method > .code-header, .trait-impl > .code-header, .invisible > .code-header {
@@ -1072,7 +1084,7 @@ body.blur > :not(#help) {
10721084
font-size: initial;
10731085
}
10741086

1075-
.impl-items .since, .impl .since, .methods .since {
1087+
.rightside {
10761088
padding-left: 12px;
10771089
padding-right: 2px;
10781090
position: initial;
@@ -1144,10 +1156,6 @@ a.test-arrow:hover{
11441156
font-weight: 300;
11451157
}
11461158

1147-
.since + .srclink {
1148-
padding-left: 10px;
1149-
}
1150-
11511159
.item-spacer {
11521160
width: 100%;
11531161
height: 12px;

src/librustdoc/html/static/css/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ nav.main .separator {
222222
a {
223223
color: #39AFD7;
224224
}
225-
a.srclink,
225+
226226
a#toggle-all-docs,
227227
a.anchor,
228228
.small-section-header a,

src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ nav.main .separator {
180180
a {
181181
color: #D2991D;
182182
}
183-
a.srclink,
183+
184184
a#toggle-all-docs,
185185
a.anchor,
186186
.small-section-header a,

src/librustdoc/html/static/css/themes/light.css

+1-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ nav.main .separator {
177177
a {
178178
color: #3873AD;
179179
}
180-
a.srclink,
180+
181181
a#toggle-all-docs,
182182
a.anchor,
183183
.small-section-header a,
@@ -243,10 +243,6 @@ details.undocumented > summary::before {
243243
border-color: #bfbfbf;
244244
}
245245

246-
.since {
247-
color: grey;
248-
}
249-
250246
.result-name .primitive > i, .result-name .keyword > i {
251247
color: black;
252248
}
+26-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
<h1 class="fqn"> {#- -#}
2-
<span class="in-band"> {#- -#}
3-
{{-typ-}}
4-
{#- The breadcrumbs of the item path, like std::string -#}
5-
{%- for component in path_components -%}
6-
<a href="{{component.path | safe}}index.html">{{component.name}}</a>::<wbr>
7-
{%- endfor -%}
8-
<a class="{{item_type}}" href="#">{{name}}</a> {#- -#}
9-
<button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#}
10-
<img src="{{static_root_path | safe}}clipboard{{page.resource_suffix}}.svg" {# -#}
11-
width="19" height="18" {# -#}
12-
alt="Copy item path"> {#- -#}
13-
</button> {#- -#}
14-
</span> {#- -#}
15-
<span class="out-of-band"> {#- -#}
16-
{{- stability_since_raw | safe -}}
17-
<span id="render-detail"> {#- -#}
18-
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> {#- -#}
19-
[<span class="inner">&#x2212;</span>] {#- -#}
20-
</a> {#- -#}
1+
<div class="main-heading">
2+
<h1 class="fqn"> {#- -#}
3+
<span class="in-band"> {#- -#}
4+
{{-typ-}}
5+
{#- The breadcrumbs of the item path, like std::string -#}
6+
{%- for component in path_components -%}
7+
<a href="{{component.path | safe}}index.html">{{component.name}}</a>::<wbr>
8+
{%- endfor -%}
9+
<a class="{{item_type}}" href="#">{{name}}</a> {#- -#}
10+
<button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#}
11+
<img src="{{static_root_path | safe}}clipboard{{page.resource_suffix}}.svg" {# -#}
12+
width="19" height="18" {# -#}
13+
alt="Copy item path"> {#- -#}
14+
</button> {#- -#}
2115
</span> {#- -#}
22-
{%- if src_href -%}
23-
<a class="srclink" href="{{src_href | safe}}" title="goto source code">[src]</a>
24-
{%- endif -%}
16+
</h1> {#- -#}
17+
<span class="out-of-band"> {#- -#}
18+
{% if stability_since_raw %}
19+
{{- stability_since_raw | safe -}} ·
20+
{% endif %}
21+
{%- if src_href %}
22+
<a class="srclink" href="{{src_href | safe}}" title="goto source code">source</a> ·
23+
{% endif -%}
24+
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> {#- -#}
25+
[<span class="inner">&#x2212;</span>] {#- -#}
26+
</a> {#- -#}
2527
</span> {#- -#}
26-
</h1> {#- -#}
28+
</div>

src/test/rustdoc-gui/anchors.goml

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ reload:
1313
assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"})
1414
assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"})
1515
assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"})
16-
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"})
17-
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"})
16+
assert-css: (".srclink", {"color": "rgb(56, 115, 173)"})
17+
18+
move-cursor-to: ".main-heading .srclink"
19+
assert-css: (".srclink", {"text-decoration": "underline solid rgb(56, 115, 173)"})
1820

1921
assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"})
2022

src/test/rustdoc-gui/headings.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
1616

1717
assert-css: ("h1.fqn", {"font-size": "24px"})
18-
assert-css: ("h1.fqn", {"border-bottom-width": "1px"})
18+
assert-css: (".main-heading", {"border-bottom-width": "1px"})
1919

2020
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
2121
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@@ -55,7 +55,7 @@ assert-css: ("h6#sub-sub-heading-for-struct-impl-item-doc", {"font-size": "15.2p
5555
goto: file://|DOC_PATH|/test_docs/enum.HeavilyDocumentedEnum.html
5656

5757
assert-css: ("h1.fqn", {"font-size": "24px"})
58-
assert-css: ("h1.fqn", {"border-bottom-width": "1px"})
58+
assert-css: (".main-heading", {"border-bottom-width": "1px"})
5959

6060
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
6161
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@@ -115,7 +115,7 @@ assert-css: (".sidebar .others h3", {"border-bottom-width": "1px"}, ALL)
115115
goto: file://|DOC_PATH|/test_docs/union.HeavilyDocumentedUnion.html
116116

117117
assert-css: ("h1.fqn", {"font-size": "24px"})
118-
assert-css: ("h1.fqn", {"border-bottom-width": "1px"})
118+
assert-css: (".main-heading", {"border-bottom-width": "1px"})
119119

120120
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
121121
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
@@ -148,7 +148,7 @@ assert-css: ("h6#sub-heading-for-union-impl-item-doc", {"border-bottom-width": "
148148
goto: file://|DOC_PATH|/test_docs/macro.heavily_documented_macro.html
149149

150150
assert-css: ("h1.fqn", {"font-size": "24px"})
151-
assert-css: ("h1.fqn", {"border-bottom-width": "1px"})
151+
assert-css: (".main-heading", {"border-bottom-width": "1px"})
152152

153153
assert-css: ("h2#top-doc-prose-title", {"font-size": "20.8px"})
154154
assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})

src/test/rustdoc-gui/toggle-docs.goml

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
22
assert-attribute: ("#main-content > details.top-doc", {"open": ""})
3+
assert-text: ("#toggle-all-docs", "[−]")
34
click: "#toggle-all-docs"
45
wait-for: 1000
56
// This is now collapsed so there shouldn't be the "open" attribute on details.
67
assert-attribute-false: ("#main-content > details.top-doc", {"open": ""})
8+
assert-text: ("#toggle-all-docs", "[+]")
79
click: "#toggle-all-docs"
810
wait-for: 1000
911
// Not collapsed anymore so the "open" attribute should be back.
1012
assert-attribute: ("#main-content > details.top-doc", {"open": ""})
13+
assert-text: ("#toggle-all-docs", "[−]")

src/test/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 '//div[@id="method.zip"]//a[@class="srclink"]' "[src]"
5+
// @has foo/trait.Iterator.html '//div[@id="method.zip"]//a[@class="srclink"]' "source"
66
pub use std::iter::Iterator;

src/test/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"]' '[src]'
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"]' '[src]'
11+
// @has - '//a[@href="../src/foo/external-macro-src.rs.html#12"]' 'source'
1212
make_foo!();

src/test/rustdoc/issue-16265-1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
pub struct Foo;
22

3-
// @has issue_16265_1/traits/index.html '[src]'
3+
// @has issue_16265_1/traits/index.html 'source'
44
pub mod traits {
55
impl PartialEq for super::Foo {
6-
fn eq(&self, _: &super::Foo) -> bool { true }
6+
fn eq(&self, _: &super::Foo) -> bool {
7+
true
8+
}
79
}
810
}

src/test/rustdoc/issue-16265-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @has issue_16265_2/index.html '[src]'
1+
// @has issue_16265_2/index.html 'source'
22

33
trait Y {}
4-
impl Y for Option<u32>{}
4+
impl Y for Option<u32> {}

src/test/rustdoc/issue-26606.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
extern crate issue_26606_macro;
88

99
// @has issue_26606/constant.FOO.html
10-
// @has - '//a[@href="../src/issue_26606/issue-26606.rs.html#11"]' '[src]'
10+
// @has - '//a[@href="../src/issue_26606/issue-26606.rs.html#11"]' 'source'
1111
make_item!(FOO);

src/test/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 - '//div[@id="impl-Sized"]/h3[@class="code-header in-band"]' 'impl !Sized for Unsized'
5-
// @!has - '//div[@id="impl-Sized"]//a[@class="srclink"]' '[src]'
5+
// @!has - '//div[@id="impl-Sized"]//a[@class="srclink"]' 'source'
66
// @has - '//div[@id="impl-Sync"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized'
7-
// @!has - '//div[@id="impl-Sync"]//a[@class="srclink"]' '[src]'
7+
// @!has - '//div[@id="impl-Sync"]//a[@class="srclink"]' 'source'
88
// @has - '//div[@id="impl-Any"]/h3[@class="code-header in-band"]' 'impl<T> Any for T'
9-
// @has - '//div[@id="impl-Any"]//a[@class="srclink"]' '[src]'
9+
// @has - '//div[@id="impl-Any"]//a[@class="srclink"]' 'source'
1010
pub struct Unsized {
1111
data: [u8],
1212
}

0 commit comments

Comments
 (0)