Skip to content

Commit e5514b9

Browse files
authored
Rollup merge of #103251 - GuillaumeGomez:item-decl-highlighting, r=notriddle
Fix item declaration highlighting Fixes #103050. As mentioned in the issue, #102924 introduced this regression. This PR partially reverts it and adds a regression test. r? `@notriddle`
2 parents 62bb0c6 + b4e06a7 commit e5514b9

File tree

4 files changed

+118
-25
lines changed

4 files changed

+118
-25
lines changed

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -229,44 +229,44 @@ h1 a,
229229
color: var(--main-color);
230230
}
231231

232-
span.enum, a.enum,
233-
span.struct, a.struct,
234-
span.union, a.union,
235-
span.primitive, a.primitive,
236-
span.type, a.type,
237-
span.foreigntype, a.foreigntype {
232+
.content span.enum, .content a.enum,
233+
.content span.struct, .content a.struct,
234+
.content span.union, .content a.union,
235+
.content span.primitive, .content a.primitive,
236+
.content span.type, .content a.type,
237+
.content span.foreigntype, .content a.foreigntype {
238238
color: var(--type-link-color);
239239
}
240240

241-
span.trait, a.trait,
242-
span.traitalias, a.traitalias {
241+
.content span.trait, .content a.trait,
242+
.content span.traitalias, .content a.traitalias {
243243
color: var(--trait-link-color);
244244
}
245245

246-
span.associatedtype, a.associatedtype,
247-
span.constant, a.constant,
248-
span.static, a.static {
246+
.content span.associatedtype, .content a.associatedtype,
247+
.content span.constant, .content a.constant,
248+
.content span.static, .content a.static {
249249
color: var(--assoc-item-link-color);
250250
}
251251

252-
span.fn, a.fn,
253-
.fnname,
254-
span.method, a.method,
255-
span.tymethod, a.tymethod {
252+
.content span.fn, .content a.fn,
253+
.content .fnname,
254+
.content span.method, .content a.method,
255+
.content span.tymethod, .content a.tymethod {
256256
color: var(--function-link-color);
257257
}
258258

259-
span.attr, a.attr,
260-
span.derive, a.derive,
261-
span.macro, a.macro {
259+
.content span.attr, .content a.attr,
260+
.content span.derive, .content a.derive,
261+
.content span.macro, .content a.macro {
262262
color: var(--macro-link-color);
263263
}
264264

265-
span.mod, a.mod {
265+
.content span.mod, .content a.mod {
266266
color: var(--mod-link-color);
267267
}
268268

269-
span.keyword, a.keyword {
269+
.content span.keyword, .content a.keyword {
270270
color: var(--keyword-link-color);
271271
}
272272

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This test ensures that the color of the items in the type decl are working as expected.
2+
define-function: (
3+
"check-colors",
4+
(
5+
theme,
6+
attr_color,
7+
trait_color,
8+
struct_color,
9+
enum_color,
10+
primitive_color,
11+
constant_color,
12+
fn_color,
13+
assoc_type_color,
14+
),
15+
[
16+
("goto", "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"),
17+
("show-text", true),
18+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
19+
("reload"),
20+
("assert-css", (".item-decl .code-attribute", {"color": |attr_color|}, ALL)),
21+
("assert-css", (".item-decl .trait", {"color": |trait_color|}, ALL)),
22+
// We need to add `code` here because otherwise it would select the parent too.
23+
("assert-css", (".item-decl code .struct", {"color": |struct_color|}, ALL)),
24+
("assert-css", (".item-decl .enum", {"color": |enum_color|}, ALL)),
25+
("assert-css", (".item-decl .primitive", {"color": |primitive_color|}, ALL)),
26+
("goto", "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithoutGenerics.html"),
27+
("assert-css", (".item-decl .constant", {"color": |constant_color|}, ALL)),
28+
("assert-css", (".item-decl .fnname", {"color": |fn_color|}, ALL)),
29+
("assert-css", (".item-decl .associatedtype", {"color": |assoc_type_color|}, ALL)),
30+
],
31+
)
32+
33+
call-function: (
34+
"check-colors",
35+
{
36+
"theme": "ayu",
37+
"attr_color": "rgb(153, 153, 153)",
38+
"trait_color": "rgb(57, 175, 215)",
39+
"struct_color": "rgb(255, 160, 165)",
40+
"enum_color": "rgb(255, 160, 165)",
41+
"primitive_color": "rgb(255, 160, 165)",
42+
"constant_color": "rgb(57, 175, 215)",
43+
"fn_color": "rgb(253, 214, 135)",
44+
"assoc_type_color": "rgb(57, 175, 215)",
45+
},
46+
)
47+
call-function: (
48+
"check-colors",
49+
{
50+
"theme": "dark",
51+
"attr_color": "rgb(153, 153, 153)",
52+
"trait_color": "rgb(183, 140, 242)",
53+
"struct_color": "rgb(45, 191, 184)",
54+
"enum_color": "rgb(45, 191, 184)",
55+
"primitive_color": "rgb(45, 191, 184)",
56+
"constant_color": "rgb(210, 153, 29)",
57+
"fn_color": "rgb(43, 171, 99)",
58+
"assoc_type_color": "rgb(210, 153, 29)",
59+
},
60+
)
61+
call-function: (
62+
"check-colors",
63+
{
64+
"theme": "light",
65+
"attr_color": "rgb(153, 153, 153)",
66+
"trait_color": "rgb(110, 79, 201)",
67+
"struct_color": "rgb(173, 55, 138)",
68+
"enum_color": "rgb(173, 55, 138)",
69+
"primitive_color": "rgb(173, 55, 138)",
70+
"constant_color": "rgb(56, 115, 173)",
71+
"fn_color": "rgb(173, 124, 55)",
72+
"assoc_type_color": "rgb(56, 115, 173)",
73+
},
74+
)

src/test/rustdoc-gui/sidebar.goml

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Modules")
2020
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Macros")
2121
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Structs")
2222
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Enums")
23-
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Traits")
24-
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Functions")
25-
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Type Definitions")
26-
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Unions")
27-
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Keywords")
23+
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Constants")
24+
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Traits")
25+
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
26+
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
27+
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
28+
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
2829
assert-text: ("#structs + .item-table .item-left > a", "Foo")
2930
click: "#structs + .item-table .item-left > a"
3031

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

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![crate_name = "test_docs"]
66
#![feature(rustdoc_internals)]
77
#![feature(doc_cfg)]
8+
#![feature(associated_type_defaults)]
89

910
/*!
1011
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
@@ -386,3 +387,20 @@ impl TypeWithNoDocblocks {
386387
pub unsafe fn unsafe_fn() {}
387388

388389
pub fn safe_fn() {}
390+
391+
#[repr(C)]
392+
pub struct WithGenerics<T: TraitWithNoDocblocks, S = String, E = WhoLetTheDogOut, P = i8> {
393+
s: S,
394+
t: T,
395+
e: E,
396+
p: P,
397+
}
398+
399+
pub const CONST: u8 = 0;
400+
401+
pub trait TraitWithoutGenerics {
402+
const C: u8 = CONST;
403+
type T = SomeType;
404+
405+
fn foo();
406+
}

0 commit comments

Comments
 (0)