Skip to content

Commit 22bbbe8

Browse files
borsGuillaumeGomez
authored andcommitted
Rustdoc accessibility: use real headers for doc items
Part of #87059 Partially reverts #84703 Heavily modified for beta backport needs.
1 parent 963e820 commit 22bbbe8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+271
-228
lines changed

src/librustdoc/html/render/mod.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
12141214
if out.is_empty() {
12151215
write!(
12161216
&mut out,
1217-
"<h3 class=\"notable\">Notable traits for {}</h3>\
1217+
"<div class=\"notable\">Notable traits for {}</div>\
12181218
<code class=\"content\">",
12191219
impl_.for_.print(cx)
12201220
);
@@ -1370,15 +1370,15 @@ fn render_impl(
13701370
"<div id=\"{}\" class=\"{}{} has-srclink\">",
13711371
id, item_type, in_trait_class,
13721372
);
1373-
w.write_str("<code>");
1373+
w.write_str("<h4 class=\"code-header\">");
13741374
render_assoc_item(
13751375
w,
13761376
item,
13771377
link.anchor(source_id.as_ref().unwrap_or(&id)),
13781378
ItemType::Impl,
13791379
cx,
13801380
);
1381-
w.write_str("</code>");
1381+
w.write_str("</h4>");
13821382
render_stability_since_raw(
13831383
w,
13841384
item.stable_since(tcx).as_deref(),
@@ -1396,9 +1396,10 @@ fn render_impl(
13961396
let id = cx.derive_id(source_id.clone());
13971397
write!(
13981398
w,
1399-
"<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
1399+
"<div id=\"{}\" class=\"{}{} has-srclink\">",
14001400
id, item_type, in_trait_class
14011401
);
1402+
w.write_str("<h4 class=\"code-header\">");
14021403
assoc_type(
14031404
w,
14041405
item,
@@ -1408,7 +1409,7 @@ fn render_impl(
14081409
"",
14091410
cx,
14101411
);
1411-
w.write_str("</code>");
1412+
w.write_str("</h4>");
14121413
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14131414
w.write_str("</div>");
14141415
}
@@ -1417,9 +1418,10 @@ fn render_impl(
14171418
let id = cx.derive_id(source_id.clone());
14181419
write!(
14191420
w,
1420-
"<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
1421+
"<div id=\"{}\" class=\"{}{} has-srclink\">",
14211422
id, item_type, in_trait_class
14221423
);
1424+
w.write_str("<h4 class=\"code-header\">");
14231425
assoc_const(
14241426
w,
14251427
item,
@@ -1429,7 +1431,7 @@ fn render_impl(
14291431
"",
14301432
cx,
14311433
);
1432-
w.write_str("</code>");
1434+
w.write_str("</h4>");
14331435
render_stability_since_raw(
14341436
w,
14351437
item.stable_since(tcx).as_deref(),
@@ -1444,7 +1446,8 @@ fn render_impl(
14441446
clean::AssocTypeItem(ref bounds, ref default) => {
14451447
let source_id = format!("{}.{}", item_type, name);
14461448
let id = cx.derive_id(source_id.clone());
1447-
write!(w, "<div id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class,);
1449+
write!(w, "<div id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
1450+
w.write_str("<h4 class=\"code-header\">");
14481451
assoc_type(
14491452
w,
14501453
item,
@@ -1454,7 +1457,7 @@ fn render_impl(
14541457
"",
14551458
cx,
14561459
);
1457-
w.write_str("</code>");
1460+
w.write_str("</h4>");
14581461
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14591462
w.write_str("</div>");
14601463
}
@@ -1638,12 +1641,8 @@ fn render_impl_summary(
16381641
format!(" data-aliases=\"{}\"", aliases.join(","))
16391642
};
16401643
if let Some(use_absolute) = use_absolute {
1641-
write!(
1642-
w,
1643-
"<div id=\"{}\" class=\"impl has-srclink\"{}>\
1644-
<code class=\"in-band\">",
1645-
id, aliases
1646-
);
1644+
write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
1645+
write!(w, "<h3 class=\"code-header in-band\">");
16471646
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
16481647
if show_def_docs {
16491648
for it in &i.inner_impl().items {
@@ -1654,12 +1653,12 @@ fn render_impl_summary(
16541653
}
16551654
}
16561655
}
1657-
w.write_str("</code>");
1656+
w.write_str("</h3>");
16581657
} else {
16591658
write!(
16601659
w,
16611660
"<div id=\"{}\" class=\"impl has-srclink\"{}>\
1662-
<code class=\"in-band\">{}</code>",
1661+
<h3 class=\"code-header in-band\">{}</h3>",
16631662
id,
16641663
aliases,
16651664
i.inner_impl().print(false, cx)

src/librustdoc/html/render/print_item.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
585585
if toggled {
586586
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
587587
}
588-
write!(w, "<div id=\"{}\" class=\"method has-srclink\"><code>", id);
588+
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
589+
write!(w, "<h4 class=\"code-header\">");
589590
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
590-
w.write_str("</code>");
591+
w.write_str("</h4>");
591592
render_stability_since(w, m, t, cx.tcx());
592593
write_srclink(cx, m, w);
593594
w.write_str("</div>");

src/librustdoc/html/static/main.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,10 @@ function hideThemeButtonState() {
703703
}
704704
}
705705

706-
var code = document.createElement("code");
706+
var code = document.createElement("h3");
707707
code.innerHTML = struct.text;
708+
addClass(code, "code-header");
709+
addClass(code, "in-band");
708710

709711
onEachLazy(code.getElementsByTagName("a"), function(elem) {
710712
var href = elem.getAttribute("href");

src/librustdoc/html/static/rustdoc.css

+53-13
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,25 @@ h1.fqn {
134134
h1.fqn > .in-band > a:hover {
135135
text-decoration: underline;
136136
}
137-
h2, h3, h4 {
137+
#main > h2, #main > h3, #main > h4 {
138138
border-bottom: 1px solid;
139139
}
140-
.impl, .method,
141-
.type:not(.container-rustdoc), .associatedconstant,
142-
.associatedtype {
140+
h3.code-header, h4.code-header {
141+
font-size: 1em;
142+
font-weight: 600;
143+
border: none;
144+
padding: 0;
145+
margin: 0;
146+
}
147+
.impl,
148+
.impl-items .method,
149+
.methods .method,
150+
.impl-items .type,
151+
.methods .type,
152+
.impl-items .associatedconstant,
153+
.methods .associatedconstant,
154+
.impl-items .associatedtype,
155+
.methods .associatedtype {
143156
flex-basis: 100%;
144157
font-weight: 600;
145158
margin-top: 16px;
@@ -190,7 +203,34 @@ summary {
190203
outline: none;
191204
}
192205

193-
code, pre, a.test-arrow {
206+
/* Fix some style changes due to normalize.css 8 */
207+
208+
td,
209+
th {
210+
padding: 0;
211+
}
212+
213+
table {
214+
border-collapse: collapse;
215+
}
216+
217+
button,
218+
input,
219+
optgroup,
220+
select,
221+
textarea {
222+
color: inherit;
223+
font: inherit;
224+
margin: 0;
225+
}
226+
227+
/* end tweaks for normalize.css 8 */
228+
229+
details:not(.rustdoc-toggle) summary {
230+
margin-bottom: .6em;
231+
}
232+
233+
code, pre, a.test-arrow, .code-header {
194234
font-family: "Source Code Pro", monospace;
195235
}
196236
.docblock code, .docblock-short code {
@@ -474,9 +514,10 @@ nav.sub {
474514
font-weight: normal;
475515
}
476516

477-
.method > code, .trait-impl > code, .invisible > code {
517+
.method > .code-header, .trait-impl > .code-header, .invisible > .code-header {
478518
max-width: calc(100% - 41px);
479519
display: block;
520+
flex-grow: 1;
480521
}
481522

482523
.invisible {
@@ -490,7 +531,7 @@ nav.sub {
490531
padding: 0px;
491532
}
492533

493-
.in-band > code {
534+
.in-band > code, .in-band > .code-header {
494535
display: inline-block;
495536
}
496537

@@ -585,7 +626,7 @@ nav.sub {
585626
.content .item-info {
586627
position: relative;
587628
margin-left: 33px;
588-
margin-top: -13px;
629+
margin-top: -6px;
589630
}
590631

591632
.sub-variant > div > .item-info {
@@ -596,7 +637,7 @@ nav.sub {
596637
content: '⬑';
597638
font-size: 25px;
598639
position: absolute;
599-
top: -6px;
640+
top: 0px;
600641
left: -19px;
601642
}
602643

@@ -690,7 +731,7 @@ a {
690731
}
691732

692733
.invisible > .srclink,
693-
.method > code + .srclink {
734+
.method > .code-header + .srclink {
694735
position: absolute;
695736
top: 0;
696737
right: 0;
@@ -912,7 +953,7 @@ body.blur > :not(#help) {
912953
.impl-items .since, .impl .since, .methods .since {
913954
flex-grow: 0;
914955
padding-left: 12px;
915-
padding-right: 2px;
956+
padding-right: 6px;
916957
position: initial;
917958
}
918959

@@ -1045,8 +1086,7 @@ a.test-arrow:hover{
10451086
display: block;
10461087
}
10471088

1048-
1049-
:target > code {
1089+
:target > code, :target > .code-header {
10501090
opacity: 1;
10511091
}
10521092

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pre, .rustdoc.source .example-wrap {
133133
color: #708090;
134134
background-color: rgba(255, 236, 164, 0.06);
135135
padding-right: 4px;
136-
border-right: 1px solid #ffb44c;
137136
}
138137

139138
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 {
@@ -334,7 +333,7 @@ a.test-arrow:hover {
334333
color: #999;
335334
}
336335

337-
:target > code, :target > .in-band {
336+
:target, :target > * {
338337
background: rgba(255, 236, 164, 0.06);
339338
border-right: 3px solid rgba(255, 180, 76, 0.85);
340339
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ a.test-arrow:hover{
282282
color: #999;
283283
}
284284

285-
:target > code, :target > .in-band {
285+
:target, :target > * {
286286
background-color: #494a3d;
287-
border-right: 3px solid #bb7410;
288287
}
289288

290289
pre.compile_fail {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,8 @@ a.test-arrow:hover{
275275
color: #999;
276276
}
277277

278-
:target > code, :target > .in-band {
278+
:target, :target > * {
279279
background: #FDFFD3;
280-
border-right: 3px solid #ffb44c;
281280
}
282281

283282
pre.compile_fail {

src/test/rustdoc-gui/src/settings/.package-cache

Whitespace-only changes.

src/test/rustdoc/assoc-consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub trait Foo {
1313
pub struct Bar;
1414

1515
impl Foo for Bar {
16-
// @has assoc_consts/struct.Bar.html '//code' 'impl Foo for Bar'
16+
// @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Foo for Bar'
1717
// @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize'
1818
const FOO: usize = 12;
1919
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
@@ -77,7 +77,7 @@ pub trait Qux {
7777
const QUX_DEFAULT2: u32 = 3;
7878
}
7979

80-
// @has assoc_consts/struct.Bar.html '//code' 'impl Qux for Bar'
80+
// @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Qux for Bar'
8181
impl Qux for Bar {
8282
// @has - '//*[@id="associatedconstant.QUX0"]' 'const QUX0: u8'
8383
// @has - '//*[@class="docblock"]' "Docs for QUX0 in trait."

src/test/rustdoc/assoc-types.rs

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

33
// @has assoc_types/trait.Index.html
44
pub trait Index<I: ?Sized> {
5-
// @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
5+
// @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized'
66
type Output: ?Sized;
7-
// @has - '//*[@id="tymethod.index"]//code' \
7+
// @has - '//*[@id="tymethod.index"]//h4[@class="code-header"]' \
88
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
9-
// @has - '//*[@id="tymethod.index"]//code//a[@href="trait.Index.html#associatedtype.Output"]' \
9+
// @has - '//*[@id="tymethod.index"]//h4[@class="code-header"]//a[@href="trait.Index.html#associatedtype.Output"]' \
1010
// "Output"
1111
fn index<'a>(&'a self, index: I) -> &'a Self::Output;
1212
}

src/test/rustdoc/async-fn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub async fn quux() -> impl Bar {
3535
}
3636

3737
// @has async_fn/struct.Foo.html
38-
// @matches - '//code' 'pub async fn f\(\)$'
39-
// @matches - '//code' 'pub async unsafe fn g\(\)$'
40-
// @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
38+
// @matches - '//h4[@class="code-header"]' 'pub async fn f\(\)$'
39+
// @matches - '//h4[@class="code-header"]' 'pub async unsafe fn g\(\)$'
40+
// @matches - '//h4[@class="code-header"]' 'pub async fn mut_self\(self, first: usize\)$'
4141
pub struct Foo;
4242

4343
impl Foo {

src/test/rustdoc/blanket-reexport-item.rs

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

3-
// @has foo/struct.S.html '//div[@id="impl-Into%3CU%3E"]//code' 'impl<T, U> Into<U> for T'
3+
// @has foo/struct.S.html '//div[@id="impl-Into%3CU%3E"]//h3[@class="code-header in-band"]' 'impl<T, U> Into<U> for T'
44
pub struct S2 {}
55
mod m {
66
pub struct S {}

src/test/rustdoc/const-display.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ pub const unsafe fn bar_not_gated() -> u32 { 42 }
3838
pub struct Foo;
3939

4040
impl Foo {
41-
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub unsafe fn gated() -> u32'
41+
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/h4[@class="code-header"]' 'pub fn gated() -> u32'
42+
#[stable(feature = "rust1", since = "1.0.0")]
43+
#[rustc_const_unstable(feature="foo", issue = "none")]
44+
pub const fn gated() -> u32 { 42 }
45+
4246
#[stable(feature = "rust1", since = "1.0.0")]
4347
#[rustc_const_unstable(feature="foo", issue = "none")]
4448
pub const unsafe fn gated() -> u32 { 42 }
4549

46-
// @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/code' 'pub const fn stable_impl() -> u32'
50+
// @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/h4[@class="code-header"]' 'pub const fn stable_impl() -> u32'
4751
// @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)'
4852
#[stable(feature = "rust1", since = "1.0.0")]
4953
#[rustc_const_stable(feature = "rust1", since = "1.2.0")]

src/test/rustdoc/const-generics/add-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Simd<T, const WIDTH: usize> {
88
inner: T,
99
}
1010

11-
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//div/code' 'impl Add<Simd<u8, 16_usize>> for Simd<u8, 16>'
11+
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//div/h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16_usize>> for Simd<u8, 16>'
1212
impl Add for Simd<u8, 16> {
1313
type Output = Self;
1414

0 commit comments

Comments
 (0)