Skip to content

Commit 5782f01

Browse files
committed
Auto merge of #87390 - notriddle:notriddle/rustdoc-headers-patch, r=GuillaumeGomez
Rustdoc accessibility: use real headers for doc items Part of #87059 Partially reverts #84703 Preview at: https://notriddle.com/notriddle-rustdoc-test/real-headers/std/index.html
2 parents 9c25eb7 + 76a3b60 commit 5782f01

Some content is hidden

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

79 files changed

+231
-218
lines changed

src/librustdoc/html/render/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
11941194
if out.is_empty() {
11951195
write!(
11961196
&mut out,
1197-
"<h3 class=\"notable\">Notable traits for {}</h3>\
1197+
"<div class=\"notable\">Notable traits for {}</div>\
11981198
<code class=\"content\">",
11991199
impl_.for_.print(cx)
12001200
);
@@ -1350,15 +1350,15 @@ fn render_impl(
13501350
);
13511351
render_rightside(w, cx, item, containing_item);
13521352
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1353-
w.write_str("<code>");
1353+
w.write_str("<h4 class=\"code-header\">");
13541354
render_assoc_item(
13551355
w,
13561356
item,
13571357
link.anchor(source_id.as_ref().unwrap_or(&id)),
13581358
ItemType::Impl,
13591359
cx,
13601360
);
1361-
w.write_str("</code>");
1361+
w.write_str("</h4>");
13621362
w.write_str("</div>");
13631363
}
13641364
}
@@ -1371,7 +1371,7 @@ fn render_impl(
13711371
id, item_type, in_trait_class
13721372
);
13731373
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1374-
w.write_str("<code>");
1374+
w.write_str("<h4 class=\"code-header\">");
13751375
assoc_type(
13761376
w,
13771377
item,
@@ -1381,7 +1381,7 @@ fn render_impl(
13811381
"",
13821382
cx,
13831383
);
1384-
w.write_str("</code>");
1384+
w.write_str("</h4>");
13851385
w.write_str("</div>");
13861386
}
13871387
clean::AssocConstItem(ref ty, ref default) => {
@@ -1394,7 +1394,7 @@ fn render_impl(
13941394
);
13951395
render_rightside(w, cx, item, containing_item);
13961396
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1397-
w.write_str("<code>");
1397+
w.write_str("<h4 class=\"code-header\">");
13981398
assoc_const(
13991399
w,
14001400
item,
@@ -1404,15 +1404,15 @@ fn render_impl(
14041404
"",
14051405
cx,
14061406
);
1407-
w.write_str("</code>");
1407+
w.write_str("</h4>");
14081408
w.write_str("</div>");
14091409
}
14101410
clean::AssocTypeItem(ref bounds, ref default) => {
14111411
let source_id = format!("{}.{}", item_type, name);
14121412
let id = cx.derive_id(source_id.clone());
14131413
write!(w, "<div id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
14141414
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1415-
w.write_str("<code>");
1415+
w.write_str("<h4 class=\"code-header\">");
14161416
assoc_type(
14171417
w,
14181418
item,
@@ -1422,7 +1422,7 @@ fn render_impl(
14221422
"",
14231423
cx,
14241424
);
1425-
w.write_str("</code>");
1425+
w.write_str("</h4>");
14261426
w.write_str("</div>");
14271427
}
14281428
clean::StrippedItem(..) => return,
@@ -1613,7 +1613,7 @@ pub(crate) fn render_impl_summary(
16131613
write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
16141614
render_rightside(w, cx, &i.impl_item, containing_item);
16151615
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1616-
write!(w, "<code class=\"in-band\">");
1616+
write!(w, "<h3 class=\"code-header in-band\">");
16171617

16181618
if let Some(use_absolute) = use_absolute {
16191619
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
@@ -1629,7 +1629,7 @@ pub(crate) fn render_impl_summary(
16291629
} else {
16301630
write!(w, "{}", i.inner_impl().print(false, cx));
16311631
}
1632-
write!(w, "</code>");
1632+
write!(w, "</h3>");
16331633

16341634
let is_trait = i.inner_impl().trait_.is_some();
16351635
if is_trait {

src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
621621
render_stability_since(w, m, t, cx.tcx());
622622
write_srclink(cx, m, w);
623623
write!(w, "</div>");
624-
write!(w, "<code>");
624+
write!(w, "<h4 class=\"code-header\">");
625625
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
626-
w.write_str("</code>");
626+
w.write_str("</h4>");
627627
w.write_str("</div>");
628628
if toggled {
629629
write!(w, "</summary>");

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ h1.fqn > .in-band > a:hover {
146146
h2, h3, h4 {
147147
border-bottom: 1px solid;
148148
}
149+
h3.code-header, h4.code-header {
150+
font-size: 1em;
151+
font-weight: 600;
152+
border: none;
153+
padding: 0;
154+
margin: 0;
155+
}
149156
.impl,
150157
.impl-items .method,
151158
.methods .method,
@@ -233,7 +240,7 @@ details:not(.rustdoc-toggle) summary {
233240
margin-bottom: .6em;
234241
}
235242

236-
code, pre, a.test-arrow {
243+
code, pre, a.test-arrow, .code-header {
237244
font-family: "Source Code Pro", monospace;
238245
}
239246
.docblock code, .docblock-short code {
@@ -521,7 +528,7 @@ nav.sub {
521528
font-weight: normal;
522529
}
523530

524-
.method > code, .trait-impl > code, .invisible > code {
531+
.method > .code-header, .trait-impl > .code-header, .invisible > .code-header {
525532
max-width: calc(100% - 41px);
526533
display: block;
527534
}
@@ -537,7 +544,7 @@ nav.sub {
537544
padding: 0px;
538545
}
539546

540-
.in-band > code {
547+
.in-band > code, .in-band > .code-header {
541548
display: inline-block;
542549
}
543550

@@ -743,7 +750,7 @@ a {
743750
}
744751

745752
.invisible > .srclink,
746-
.method > code + .srclink {
753+
.method > .code-header + .srclink {
747754
position: absolute;
748755
top: 0;
749756
right: 0;
@@ -1104,7 +1111,7 @@ a.test-arrow:hover{
11041111
left: -10px;
11051112
}
11061113

1107-
:target > code {
1114+
:target > code, :target > .code-header {
11081115
opacity: 1;
11091116
}
11101117

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ a.test-arrow:hover {
334334
color: #999;
335335
}
336336

337-
:target, :target * {
337+
:target, :target > * {
338338
background: rgba(255, 236, 164, 0.06);
339339
}
340340

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

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

285-
:target, :target * {
285+
:target, :target > * {
286286
background-color: #494a3d;
287287
}
288288

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ a.test-arrow:hover{
274274
color: #999;
275275
}
276276

277-
:target, :target * {
277+
:target, :target > * {
278278
background: #FDFFD3;
279279
}
280280

src/librustdoc/html/static/js/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,9 @@ function hideThemeButtonState() {
706706
}
707707
}
708708

709-
var code = document.createElement("code");
709+
var code = document.createElement("h3");
710710
code.innerHTML = struct.text;
711+
addClass(code, "code-header");
711712
addClass(code, "in-band");
712713

713714
onEachLazy(code.getElementsByTagName("a"), function(elem) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ goto: file://|DOC_PATH|/lib2/struct.Foo.html
22
// This test checks that the font weight is correctly applied.
33
assert-css: ("//*[@class='docblock type-decl']//a[text()='Alias']", {"font-weight": "400"})
44
assert-css: ("//*[@class='structfield small-section-header']//a[text()='Alias']", {"font-weight": "400"})
5-
assert-css: ("#method\.a_method > code", {"font-weight": "600"})
6-
assert-css: ("#associatedtype\.X > code", {"font-weight": "600"})
7-
assert-css: ("#associatedconstant\.Y > code", {"font-weight": "600"})
5+
assert-css: ("#method\.a_method > .code-header", {"font-weight": "600"})
6+
assert-css: ("#associatedtype\.X > .code-header", {"font-weight": "600"})
7+
assert-css: ("#associatedconstant\.Y > .code-header", {"font-weight": "600"})
88

99
goto: file://|DOC_PATH|/test_docs/type.SomeType.html
1010
assert-css: (".top-doc .docblock p", {"font-weight": "400"}, ALL)

src/test/rustdoc-gui/implementors.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ assert-count: ("#implementors-list > .impl", 2)
88
assert: ("#implementors-list > .impl:nth-child(1) > a.anchor")
99
assert-attribute: ("#implementors-list > .impl:nth-child(1)", {"id": "impl-Whatever"})
1010
assert-attribute: ("#implementors-list > .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever"})
11-
assert: "#implementors-list > .impl:nth-child(1) > code.in-band"
11+
assert: "#implementors-list > .impl:nth-child(1) > .code-header.in-band"
1212

1313
assert: ("#implementors-list > .impl:nth-child(2) > a.anchor")
1414
assert-attribute: ("#implementors-list > .impl:nth-child(2)", {"id": "impl-Whatever-1"})
1515
assert-attribute: ("#implementors-list > .impl:nth-child(2) > a.anchor", {"href": "#impl-Whatever-1"})
16-
assert: "#implementors-list > .impl:nth-child(2) > code.in-band"
16+
assert: "#implementors-list > .impl:nth-child(2) > .code-header.in-band"

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ pub const unsafe fn bar_not_gated() -> u32 { 42 }
4949
pub struct Foo;
5050

5151
impl Foo {
52-
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub fn gated() -> u32'
52+
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/h4[@class="code-header"]' 'pub fn gated() -> u32'
5353
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
5454
#[stable(feature = "rust1", since = "1.0.0")]
5555
#[rustc_const_unstable(feature="foo", issue = "none")]
5656
pub const fn gated() -> u32 { 42 }
5757

58-
// @has 'foo/struct.Foo.html' '//div[@id="method.gated_unsafe"]/code' 'pub unsafe fn gated_unsafe() -> u32'
58+
// @has 'foo/struct.Foo.html' '//div[@id="method.gated_unsafe"]/h4[@class="code-header"]' 'pub unsafe fn gated_unsafe() -> u32'
5959
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
6060
#[stable(feature = "rust1", since = "1.0.0")]
6161
#[rustc_const_unstable(feature="foo", issue = "none")]
6262
pub const unsafe fn gated_unsafe() -> u32 { 42 }
6363

64-
// @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/code' 'pub const fn stable_impl() -> u32'
64+
// @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/h4[@class="code-header"]' 'pub const fn stable_impl() -> u32'
6565
// @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)'
6666
#[stable(feature = "rust1", since = "1.0.0")]
6767
#[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

src/test/rustdoc/const-generics/const-generics-docs.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ pub use extern_crate::WTrait;
1919

2020
// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
2121
// 'pub trait Trait<const N: usize>'
22-
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//code' 'impl Trait<1_usize> for u8'
23-
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//code' 'impl Trait<2_usize> for u8'
24-
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//code' 'impl Trait<{1 + 2}> for u8'
25-
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//code' \
22+
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1_usize> for u8'
23+
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2_usize> for u8'
24+
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
25+
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
2626
// 'impl<const N: usize> Trait<N> for [u8; N]'
2727
pub trait Trait<const N: usize> {}
2828
impl Trait<1> for u8 {}
@@ -36,7 +36,7 @@ pub struct Foo<const N: usize> where u8: Trait<N>;
3636
// @has foo/struct.Bar.html '//pre[@class="rust struct"]' 'pub struct Bar<T, const N: usize>(_)'
3737
pub struct Bar<T, const N: usize>([T; N]);
3838

39-
// @has foo/struct.Foo.html '//div[@id="impl"]/code' 'impl<const M: usize> Foo<M> where u8: Trait<M>'
39+
// @has foo/struct.Foo.html '//div[@id="impl"]/h3[@class="code-header in-band"]' 'impl<const M: usize> Foo<M> where u8: Trait<M>'
4040
impl<const M: usize> Foo<M> where u8: Trait<M> {
4141
// @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize'
4242
pub const FOO_ASSOC: usize = M + 13;
@@ -47,7 +47,7 @@ impl<const M: usize> Foo<M> where u8: Trait<M> {
4747
}
4848
}
4949

50-
// @has foo/struct.Bar.html '//div[@id="impl"]/code' 'impl<const M: usize> Bar<u8, M>'
50+
// @has foo/struct.Bar.html '//div[@id="impl"]/h3[@class="code-header in-band"]' 'impl<const M: usize> Bar<u8, M>'
5151
impl<const M: usize> Bar<u8, M> {
5252
// @has - '//*[@id="method.hey"]' \
5353
// 'pub fn hey<const N: usize>(&self) -> Foo<N> where u8: Trait<N>'

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ pub enum Order {
99
}
1010

1111
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
12-
// @has foo/struct.VSet.html '//div[@id="impl-Send"]/code' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
13-
// @has foo/struct.VSet.html '//div[@id="impl-Sync"]/code' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
12+
// @has foo/struct.VSet.html '//div[@id="impl-Send"]/h3[@class="code-header in-band"]' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
13+
// @has foo/struct.VSet.html '//div[@id="impl-Sync"]/h3[@class="code-header in-band"]' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
1414
pub struct VSet<T, const ORDER: Order> {
1515
inner: Vec<T>,
1616
}
1717

18-
// @has foo/struct.VSet.html '//div[@id="impl"]/code' 'impl<T> VSet<T, {Order::Sorted}>'
18+
// @has foo/struct.VSet.html '//div[@id="impl"]/h3[@class="code-header in-band"]' 'impl<T> VSet<T, {Order::Sorted}>'
1919
impl <T> VSet<T, {Order::Sorted}> {
2020
pub fn new() -> Self {
2121
Self { inner: Vec::new() }
2222
}
2323
}
2424

25-
// @has foo/struct.VSet.html '//div[@id="impl-1"]/code' 'impl<T> VSet<T, {Order::Unsorted}>'
25+
// @has foo/struct.VSet.html '//div[@id="impl-1"]/h3[@class="code-header in-band"]' 'impl<T> VSet<T, {Order::Unsorted}>'
2626
impl <T> VSet<T, {Order::Unsorted}> {
2727
pub fn new() -> Self {
2828
Self { inner: Vec::new() }
@@ -31,7 +31,7 @@ impl <T> VSet<T, {Order::Unsorted}> {
3131

3232
pub struct Escape<const S: &'static str>;
3333

34-
// @has foo/struct.Escape.html '//div[@id="impl"]/code' 'impl Escape<{ r#"<script>alert("Escape");</script>"# }>'
34+
// @has foo/struct.Escape.html '//div[@id="impl"]/h3[@class="code-header in-band"]' 'impl Escape<{ r#"<script>alert("Escape");</script>"# }>'
3535
impl Escape<{ r#"<script>alert("Escape");</script>"# }> {
3636
pub fn f() {}
3737
}

src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Hasher<T> {
1212
unsafe impl<T: Default> Send for Hasher<T> {}
1313

1414
// @has foo/struct.Foo.html
15-
// @has - '//code' 'impl Send for Foo'
15+
// @has - '//h3[@class="code-header in-band"]' 'impl Send for Foo'
1616
pub struct Foo {
1717
hasher: Hasher<[u8; 3]>,
1818
}

0 commit comments

Comments
 (0)