Skip to content

Commit 72e36d4

Browse files
authored
Rollup merge of #91480 - jsha:fewer-colors, r=GuillaumeGomez
rustdoc: use smaller number of colors to distinguish items This reduces visual distractions when reading method signatures. As discussed in #59845 (comment), this categorizes items into one of six colors (down from thirteen): - method, function (ochre `#AD7C37`) - trait, trait alias (dark slate blue `#6E4FC9`) - enum, struct, type alias, union, primitive (maroon `#AD378A`) - static, module, keyword, associated type, foreign type (steel blue `#3873AD`) - macro (green `#68000`) - generic params, self, Self (unmarked black `#000000`) I slightly tweaked the actual color values so they'd have the same lightness (previously the trait color stood out much more than the others). And I made the color for links in general consistently use steel blue (previously there was a slightly different color for "search-failed"). The ayu and dark themes have been updated according to the same logic. I haven't changed any of the color values in those themes, just their assignment to types. Demo: https://rustdoc.crud.net/jsha/fewer-colors/std/string/struct.String.html https://rustdoc.crud.net/jsha/fewer-colors/std/vec/struct.Vec.html https://rustdoc.crud.net/jsha/fewer-colors/std/io/trait.Read.html https://rustdoc.crud.net/jsha/fewer-colors/std/iter/trait.Iterator.html
2 parents 198fca8 + 3f517fb commit 72e36d4

File tree

9 files changed

+82
-70
lines changed

9 files changed

+82
-70
lines changed

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ fn fmt_type<'cx>(
955955
Ok((ref url, _, ref path)) if !f.alternate() => {
956956
write!(
957957
f,
958-
"<a class=\"type\" href=\"{url}#{shortty}.{name}\" \
958+
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
959959
title=\"type {path}::{name}\">{name}</a>",
960960
url = url,
961961
shortty = ItemType::AssocType,

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ fn assoc_type(
788788
) {
789789
write!(
790790
w,
791-
"{}type <a href=\"{}\" class=\"type\">{}</a>",
791+
"{}type <a href=\"{}\" class=\"associatedtype\">{}</a>",
792792
extra,
793793
naive_assoc_href(it, link, cx),
794794
it.name.as_ref().unwrap()

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

+19-11
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,35 @@ pre, .rustdoc.source .example-wrap {
167167

168168
.content .item-info::before { color: #ccc; }
169169

170-
.content span.foreigntype, .content a.foreigntype { color: #ef57ff; }
171-
.content span.union, .content a.union { color: #98a01c; }
170+
.content span.foreigntype, .content a.foreigntype { color: #ffa0a5; }
171+
.content span.union, .content a.union { color: #ffa0a5; }
172172
.content span.constant, .content a.constant,
173-
.content span.static, .content a.static { color: #6380a0; }
174-
.content span.primitive, .content a.primitive { color: #32889b; }
175-
.content span.traitalias, .content a.traitalias { color: #57d399; }
176-
.content span.keyword, .content a.keyword { color: #de5249; }
173+
.content span.static, .content a.static { color: #39AFD7; }
174+
.content span.primitive, .content a.primitive { color: #ffa0a5; }
175+
.content span.traitalias, .content a.traitalias { color: #39AFD7; }
176+
.content span.keyword, .content a.keyword { color: #39AFD7; }
177177

178178
.content span.externcrate, .content span.mod, .content a.mod {
179-
color: #acccf9;
179+
color: #39AFD7;
180180
}
181181
.content span.struct, .content a.struct {
182182
color: #ffa0a5;
183183
}
184184
.content span.enum, .content a.enum {
185-
color: #99e0c9;
185+
color: #ffa0a5;
186186
}
187187
.content span.trait, .content a.trait {
188188
color: #39AFD7;
189189
}
190190
.content span.type, .content a.type {
191-
color: #cfbcf5;
191+
color: #39AFD7;
192192
}
193+
.content span.type,
194+
.content a.type,
195+
.block a.current.type { color: #39AFD7; }
196+
.content span.associatedtype,
197+
.content a.associatedtype,
198+
.block a.current.associatedtype { color: #39AFD7; }
193199
.content span.fn, .content a.fn, .content span.method,
194200
.content a.method, .content span.tymethod,
195201
.content a.tymethod, .content .fnname {
@@ -454,11 +460,12 @@ above the `@media (max-width: 700px)` rules due to a bug in the css checker */
454460
.block a.current.derive,.content span.macro,.content a.macro,.block a.current.macro {}
455461
.content span.struct,.content a.struct,.block a.current.struct {}
456462
#titles>button:hover,#titles>button.selected {}
457-
.content span.type,.content a.type,.block a.current.type {}
463+
.content span.typedef,.content a.typedef,.block a.current.typedef {}
458464
.content span.union,.content a.union,.block a.current.union {}
459465
pre.rust .lifetime {}
460466
.stab.unstable {}
461-
h2,h3:not(.impl):not(.method):not(.type):not(.tymethod),h4:not(.method):not(.type):not(.tymethod) {}
467+
h2,
468+
h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {}
462469
.content span.enum,.content a.enum,.block a.current.enum {}
463470
.content span.constant,.content a.constant,.block a.current.constant,.content span.static,
464471
.content a.static, .block a.current.static {}
@@ -495,6 +502,7 @@ a.result-fn:focus,
495502
a.result-method:focus,
496503
a.result-tymethod:focus {}
497504
a.result-type:focus {}
505+
a.result-associatedtype:focus {}
498506
a.result-foreigntype:focus {}
499507
a.result-attr:focus,
500508
a.result-derive:focus,

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -119,47 +119,49 @@ pre, .rustdoc.source .example-wrap {
119119
a.result-trait:focus { background-color: #013191; }
120120
a.result-traitalias:focus { background-color: #013191; }
121121
a.result-mod:focus,
122-
a.result-externcrate:focus { background-color: #afc6e4; }
123-
a.result-mod:focus { background-color: #803a1b; }
124-
a.result-externcrate:focus { background-color: #396bac; }
125-
a.result-enum:focus { background-color: #5b4e68; }
122+
a.result-externcrate:focus { background-color: #884719; }
123+
a.result-enum:focus { background-color: #194e9f; }
126124
a.result-struct:focus { background-color: #194e9f; }
127-
a.result-union:focus { background-color: #b7bd49; }
125+
a.result-union:focus { background-color: #194e9f; }
128126
a.result-fn:focus,
129127
a.result-method:focus,
130128
a.result-tymethod:focus { background-color: #4950ed; }
131-
a.result-type:focus { background-color: #38902c; }
132-
a.result-foreigntype:focus { background-color: #b200d6; }
129+
a.result-type:focus { background-color: #194e9f; }
130+
a.result-associatedtype:focus { background-color: #884719; }
131+
a.result-foreigntype:focus { background-color: #194e9f; }
133132
a.result-attr:focus,
134133
a.result-derive:focus,
135134
a.result-macro:focus { background-color: #217d1c; }
136135
a.result-constant:focus,
137-
a.result-static:focus { background-color: #0063cc; }
138-
a.result-primitive:focus { background-color: #00708a; }
136+
a.result-static:focus { background-color: #884719; }
137+
a.result-primitive:focus { background-color: #194e9f; }
139138
a.result-keyword:focus { background-color: #884719; }
140139

141140
.content .item-info::before { color: #ccc; }
142141

143-
.content span.enum, .content a.enum, .block a.current.enum { color: #82b089; }
142+
.content span.enum, .content a.enum, .block a.current.enum { color: #2dbfb8; }
144143
.content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; }
145-
.content span.type, .content a.type, .block a.current.type { color: #ff7f00; }
146-
.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #dd7de8; }
144+
.content span.type, .content a.type, .block a.current.type { color: #2dbfb8; }
145+
.content span.associatedtype,
146+
.content a.associatedtype,
147+
.block a.current.associatedtype { color: #D2991D; }
148+
.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #2dbfb8; }
147149
.content span.attr, .content a.attr, .block a.current.attr,
148150
.content span.derive, .content a.derive, .block a.current.derive,
149151
.content span.macro, .content a.macro, .block a.current.macro { color: #09bd00; }
150-
.content span.union, .content a.union, .block a.current.union { color: #a6ae37; }
152+
.content span.union, .content a.union, .block a.current.union { color: #2dbfb8; }
151153
.content span.constant, .content a.constant, .block a.current.constant,
152-
.content span.static, .content a.static, .block a.current.static { color: #82a5c9; }
153-
.content span.primitive, .content a.primitive, .block a.current.primitive { color: #43aec7; }
154+
.content span.static, .content a.static, .block a.current.static { color: #D2991D; }
155+
.content span.primitive, .content a.primitive, .block a.current.primitive { color: #2dbfb8; }
154156
.content span.externcrate,
155-
.content span.mod, .content a.mod, .block a.current.mod { color: #bda000; }
157+
.content span.mod, .content a.mod, .block a.current.mod { color: #D2991D; }
156158
.content span.trait, .content a.trait, .block a.current.trait { color: #b78cf2; }
157-
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #b397da; }
159+
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #b78cf2; }
158160
.content span.fn, .content a.fn, .block a.current.fn,
159161
.content span.method, .content a.method, .block a.current.method,
160162
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
161163
.content .fnname{ color: #2BAB63; }
162-
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
164+
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #D2991D; }
163165

164166
pre.rust .comment { color: #8d8d8b; }
165167
pre.rust .doccomment { color: #8ca375; }

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

+34-30
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ h1, h2, h3, h4 {
99
color: black;
1010
}
1111
h1.fqn {
12-
border-bottom-color: #D5D5D5;
12+
border-bottom-color: #DDDDDD;
1313
}
1414
h2, h3, h4 {
1515
border-bottom-color: #DDDDDD;
@@ -31,7 +31,7 @@ pre, .rustdoc.source .example-wrap {
3131
}
3232

3333
.sidebar {
34-
background-color: #F1F1F1;
34+
background-color: #F5F5F5;
3535
}
3636

3737
/* Improve the scrollbar display on firefox */
@@ -90,7 +90,7 @@ pre, .rustdoc.source .example-wrap {
9090

9191
.line-numbers span { color: #c67e2d; }
9292
.line-numbers .line-highlighted {
93-
background-color: #f6fdb0 !important;
93+
background-color: #FDFFD3 !important;
9494
}
9595

9696
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
@@ -120,44 +120,48 @@ a.result-trait:focus { background-color: #c7b6ff; }
120120
a.result-traitalias:focus { background-color: #c7b6ff; }
121121
a.result-mod:focus,
122122
a.result-externcrate:focus { background-color: #afc6e4; }
123-
a.result-enum:focus { background-color: #b4d1b9; }
123+
a.result-enum:focus { background-color: #e7b1a0; }
124124
a.result-struct:focus { background-color: #e7b1a0; }
125-
a.result-union:focus { background-color: #b7bd49; }
125+
a.result-union:focus { background-color: #e7b1a0; }
126126
a.result-fn:focus,
127127
a.result-method:focus,
128128
a.result-tymethod:focus { background-color: #c6afb3; }
129-
a.result-type:focus { background-color: #ffc891; }
130-
a.result-foreigntype:focus { background-color: #f5c4ff; }
129+
a.result-type:focus { background-color: #e7b1a0; }
130+
a.result-associatedtype:focus { background-color: #afc6e4; }
131+
a.result-foreigntype:focus { background-color: #e7b1a0; }
131132
a.result-attr:focus,
132133
a.result-derive:focus,
133134
a.result-macro:focus { background-color: #8ce488; }
134135
a.result-constant:focus,
135-
a.result-static:focus { background-color: #c3e0ff; }
136-
a.result-primitive:focus { background-color: #9aecff; }
137-
a.result-keyword:focus { background-color: #f99650; }
136+
a.result-static:focus { background-color: #afc6e4; }
137+
a.result-primitive:focus { background-color: #e7b1a0; }
138+
a.result-keyword:focus { background-color: #afc6e4; }
138139

139140
.content .item-info::before { color: #ccc; }
140141

141-
.content span.enum, .content a.enum, .block a.current.enum { color: #508157; }
142-
.content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; }
143-
.content span.type, .content a.type, .block a.current.type { color: #ba5d00; }
144-
.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #cd00e2; }
142+
.content span.enum, .content a.enum, .block a.current.enum { color: #AD378A; }
143+
.content span.struct, .content a.struct, .block a.current.struct { color: #AD378A; }
144+
.content span.type, .content a.type, .block a.current.type { color: #AD378A; }
145+
.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #3873AD; }
146+
.content span.associatedtype,
147+
.content a.associatedtype,
148+
.block a.current.associatedtype { color: #3873AD; }
145149
.content span.attr, .content a.attr, .block a.current.attr,
146150
.content span.derive, .content a.derive, .block a.current.derive,
147151
.content span.macro, .content a.macro, .block a.current.macro { color: #068000; }
148-
.content span.union, .content a.union, .block a.current.union { color: #767b27; }
152+
.content span.union, .content a.union, .block a.current.union { color: #AD378A; }
149153
.content span.constant, .content a.constant, .block a.current.constant,
150-
.content span.static, .content a.static, .block a.current.static { color: #546e8a; }
151-
.content span.primitive, .content a.primitive, .block a.current.primitive { color: #2c8093; }
154+
.content span.static, .content a.static, .block a.current.static { color: #3873AD; }
155+
.content span.primitive, .content a.primitive, .block a.current.primitive { color: #AD378A; }
152156
.content span.externcrate,
153-
.content span.mod, .content a.mod, .block a.current.mod { color: #4d76ae; }
154-
.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; }
155-
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #6841f1; }
157+
.content span.mod, .content a.mod, .block a.current.mod { color: #3873AD; }
158+
.content span.trait, .content a.trait, .block a.current.trait { color: #6E4FC9; }
159+
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #5137AD; }
156160
.content span.fn, .content a.fn, .block a.current.fn,
157161
.content span.method, .content a.method, .block a.current.method,
158162
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
159-
.content .fnname { color: #9a6e31; }
160-
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
163+
.content .fnname { color: #AD7C37; }
164+
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #3873AD; }
161165

162166
nav:not(.sidebar) {
163167
border-bottom-color: #e0e0e0;
@@ -268,7 +272,7 @@ pre.rust .question-mark {
268272
}
269273

270274
a.test-arrow {
271-
background-color: rgba(78, 139, 202, 0.2);
275+
background-color: rgb(78, 139, 202, 0.2);
272276
}
273277

274278
a.test-arrow:hover{
@@ -285,7 +289,7 @@ a.test-arrow:hover{
285289
}
286290

287291
:target {
288-
border-right: 3px solid #ffb44c;
292+
border-right: 3px solid #AD7C37;
289293
}
290294

291295
pre.compile_fail {
@@ -337,7 +341,7 @@ pre.ignore:hover, .information:hover + pre.ignore {
337341
}
338342

339343
.search-failed a {
340-
color: #0089ff;
344+
color: #3873AD;
341345
}
342346

343347
.tooltip::after {
@@ -374,18 +378,18 @@ pre.ignore:hover, .information:hover + pre.ignore {
374378

375379
@media (max-width: 700px) {
376380
.sidebar-menu {
377-
background-color: #F1F1F1;
381+
background-color: #F5F5F5;
378382
border-bottom-color: #e0e0e0;
379383
border-right-color: #e0e0e0;
380384
}
381385

382386
.sidebar-elems {
383-
background-color: #F1F1F1;
387+
background-color: #F5F5F5;
384388
border-right-color: #000;
385389
}
386390

387391
#sidebar-filler {
388-
background-color: #F1F1F1;
392+
background-color: #F5F5F5;
389393
border-bottom-color: #e0e0e0;
390394
}
391395
}
@@ -453,13 +457,13 @@ kbd {
453457
}
454458

455459
#sidebar-toggle {
456-
background-color: #F1F1F1;
460+
background-color: #F5F5F5;
457461
}
458462
#sidebar-toggle:hover {
459463
background-color: #E0E0E0;
460464
}
461465
#source-sidebar {
462-
background-color: #F1F1F1;
466+
background-color: #F5F5F5;
463467
}
464468
#source-sidebar > .title {
465469
border-bottom-color: #ccc;

src/test/rustdoc-gui/anchors.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ reload:
1212

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)"})
15-
assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 68, 142)"})
15+
assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"})
1616
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"})
1717
assert-css: (".srclink", {"color": "rgb(0, 0, 0)"})
1818

src/test/rustdoc-gui/font-weight.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ assert-css: (
3737
{"font-weight": "400"},
3838
)
3939

40-
assert-count: (".methods .type", 1)
41-
assert-css: (".methods .type", {"font-weight": "600"})
40+
assert-count: (".methods .associatedtype", 1)
41+
assert-css: (".methods .associatedtype", {"font-weight": "600"})
4242
assert-count: (".methods .constant", 1)
4343
assert-css: (".methods .constant", {"font-weight": "600"})
4444
assert-css: (".methods .method", {"font-weight": "600"})

src/test/rustdoc/assoc-item-cast.rs

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

3-
43
pub trait Expression {
54
type SqlType;
65
}
@@ -11,5 +10,5 @@ pub trait AsExpression<T> {
1110
}
1211

1312
// @has foo/type.AsExprOf.html
14-
// @has - '//*[@class="rust typedef"]' 'type AsExprOf<Item, Type> = <Item as AsExpression<Type>>::Expression;'
13+
// @has - '//pre[@class="rust typedef"]' 'type AsExprOf<Item, Type> = <Item as AsExpression<Type>>::Expression;'
1514
pub type AsExprOf<Item, Type> = <Item as AsExpression<Type>>::Expression;

src/test/rustdoc/trait-impl-items-links-and-anchors.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ pub trait MyTrait {
66
fn defaulted_override(&self) {}
77
}
88

9-
109
impl MyTrait for String {
11-
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-1"]//a[@class="type"]/@href' #associatedtype.Assoc
10+
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-1"]//a[@class="associatedtype"]/@href' #associatedtype.Assoc
1211
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-1"]//a[@class="anchor"]/@href' #associatedtype.Assoc-1
1312
type Assoc = ();
1413
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-1"]//a[@class="constant"]/@href' #associatedconstant.VALUE
@@ -23,7 +22,7 @@ impl MyTrait for String {
2322
}
2423

2524
impl MyTrait for Vec<u8> {
26-
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-2"]//a[@class="type"]/@href' #associatedtype.Assoc
25+
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-2"]//a[@class="associatedtype"]/@href' #associatedtype.Assoc
2726
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-2"]//a[@class="anchor"]/@href' #associatedtype.Assoc-2
2827
type Assoc = ();
2928
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-2"]//a[@class="constant"]/@href' #associatedconstant.VALUE
@@ -39,7 +38,7 @@ impl MyTrait for Vec<u8> {
3938

4039
impl MyTrait for MyStruct {
4140
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3
42-
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
41+
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="associatedtype"]/@href' trait.MyTrait.html#associatedtype.Assoc
4342
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
4443
type Assoc = bool;
4544
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3

0 commit comments

Comments
 (0)