Skip to content

Commit da86509

Browse files
committed
Auto merge of #84703 - GuillaumeGomez:cleanup-dom, r=jsha
Clean up dom The commits come from #84480. They were errors reported by the `tidy` script that we will use to ensure that the HTML generated by rustdoc is valid. I checked carefully that there were no difference so in principle it should be exactly the same rendering but a double-check would be very appreciated in case I missed something. Extra note: `<h4>` and some `<h3>` tags were replaced by `<div>` because they're not supposed to contain tags as they currently do. r? `@jsha`
2 parents dbe459d + 0daf8ac commit da86509

Some content is hidden

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

61 files changed

+256
-241
lines changed

src/librustdoc/html/layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ crate fn redirect(url: &str) -> String {
235235
<html lang="en">
236236
<head>
237237
<meta http-equiv="refresh" content="0;URL={url}">
238+
<title>Redirection</title>
238239
</head>
239240
<body>
240241
<p>Redirecting to <a href="{url}">{url}</a>...</p>

src/librustdoc/html/render/mod.rs

+32-16
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,11 @@ fn render_impl(
13691369
})
13701370
})
13711371
.map(|item| format!("{}.{}", item.type_(), name));
1372-
write!(w, "<h4 id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
1372+
write!(
1373+
w,
1374+
"<div id=\"{}\" class=\"{}{} has-srclink\">",
1375+
id, item_type, in_trait_class,
1376+
);
13731377
w.write_str("<code>");
13741378
render_assoc_item(
13751379
w,
@@ -1388,13 +1392,17 @@ fn render_impl(
13881392
);
13891393
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
13901394
write_srclink(cx, item, w);
1391-
w.write_str("</h4>");
1395+
w.write_str("</div>");
13921396
}
13931397
}
13941398
clean::TypedefItem(ref tydef, _) => {
13951399
let source_id = format!("{}.{}", ItemType::AssocType, name);
13961400
let id = cx.derive_id(source_id.clone());
1397-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1401+
write!(
1402+
w,
1403+
"<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
1404+
id, item_type, in_trait_class
1405+
);
13981406
assoc_type(
13991407
w,
14001408
item,
@@ -1406,12 +1414,16 @@ fn render_impl(
14061414
);
14071415
w.write_str("</code>");
14081416
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1409-
w.write_str("</h4>");
1417+
w.write_str("</div>");
14101418
}
14111419
clean::AssocConstItem(ref ty, ref default) => {
14121420
let source_id = format!("{}.{}", item_type, name);
14131421
let id = cx.derive_id(source_id.clone());
1414-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1422+
write!(
1423+
w,
1424+
"<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
1425+
id, item_type, in_trait_class
1426+
);
14151427
assoc_const(
14161428
w,
14171429
item,
@@ -1431,12 +1443,12 @@ fn render_impl(
14311443
);
14321444
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14331445
write_srclink(cx, item, w);
1434-
w.write_str("</h4>");
1446+
w.write_str("</div>");
14351447
}
14361448
clean::AssocTypeItem(ref bounds, ref default) => {
14371449
let source_id = format!("{}.{}", item_type, name);
14381450
let id = cx.derive_id(source_id.clone());
1439-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1451+
write!(w, "<div id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class,);
14401452
assoc_type(
14411453
w,
14421454
item,
@@ -1448,7 +1460,7 @@ fn render_impl(
14481460
);
14491461
w.write_str("</code>");
14501462
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1451-
w.write_str("</h4>");
1463+
w.write_str("</div>");
14521464
}
14531465
clean::StrippedItem(..) => return,
14541466
_ => panic!("can't make docs for trait item with name {:?}", item.name),
@@ -1577,7 +1589,8 @@ fn render_impl(
15771589
if let Some(use_absolute) = use_absolute {
15781590
write!(
15791591
w,
1580-
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">",
1592+
"{}<div id=\"{}\" class=\"impl has-srclink\"{}>\
1593+
<code class=\"in-band\">",
15811594
open_details(&mut close_tags, is_implementing_trait),
15821595
id,
15831596
aliases
@@ -1604,7 +1617,8 @@ fn render_impl(
16041617
} else {
16051618
write!(
16061619
w,
1607-
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
1620+
"{}<div id=\"{}\" class=\"impl has-srclink\"{}>\
1621+
<code class=\"in-band\">{}</code>",
16081622
open_details(&mut close_tags, is_implementing_trait),
16091623
id,
16101624
aliases,
@@ -1621,9 +1635,9 @@ fn render_impl(
16211635
);
16221636
write_srclink(cx, &i.impl_item, w);
16231637
if !toggled {
1624-
w.write_str("</h3>");
1638+
w.write_str("</div>");
16251639
} else {
1626-
w.write_str("</h3></summary>");
1640+
w.write_str("</div></summary>");
16271641
}
16281642

16291643
if trait_.is_some() {
@@ -1649,10 +1663,12 @@ fn render_impl(
16491663
);
16501664
}
16511665
}
1652-
w.write_str("<div class=\"impl-items\">");
1653-
w.push_buffer(default_impl_items);
1654-
w.push_buffer(impl_items);
1655-
close_tags.insert_str(0, "</div>");
1666+
if !default_impl_items.is_empty() || !impl_items.is_empty() {
1667+
w.write_str("<div class=\"impl-items\">");
1668+
w.push_buffer(default_impl_items);
1669+
w.push_buffer(impl_items);
1670+
close_tags.insert_str(0, "</div>");
1671+
}
16561672
w.write_str(&close_tags);
16571673
}
16581674

src/librustdoc/html/render/print_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
7575
);
7676
}
7777
}
78-
write!(buf, "<a class=\"{}\" href=\"\">{}</a>", item.type_(), item.name.as_ref().unwrap());
78+
write!(buf, "<a class=\"{}\" href=\"#\">{}</a>", item.type_(), item.name.as_ref().unwrap());
7979
write!(
8080
buf,
8181
"<button id=\"copy-path\" onclick=\"copy_path(this)\">\
@@ -585,12 +585,12 @@ 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, "<h3 id=\"{id}\" class=\"method\"><code>", id = id);
588+
write!(w, "<div id=\"{}\" class=\"method has-srclink\"><code>", id);
589589
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
590590
w.write_str("</code>");
591591
render_stability_since(w, m, t, cx.tcx());
592592
write_srclink(cx, m, w);
593-
w.write_str("</h3>");
593+
w.write_str("</div>");
594594
if toggled {
595595
write!(w, "</summary>");
596596
w.push_buffer(content);

src/librustdoc/html/static/rustdoc.css

+30-46
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ h2 {
117117
h3 {
118118
font-size: 1.3em;
119119
}
120-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.notable),
121-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
120+
h1, h2, h3, h4 {
122121
font-weight: 500;
123122
margin: 20px 0 15px 0;
124123
padding-bottom: 6px;
@@ -135,30 +134,38 @@ h1.fqn {
135134
h1.fqn > .in-band > a:hover {
136135
text-decoration: underline;
137136
}
138-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
139-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
137+
h2, h3, h4 {
140138
border-bottom: 1px solid;
141139
}
142-
h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant, h4.associatedtype {
140+
.impl, .method,
141+
.type, .associatedconstant,
142+
.associatedtype {
143143
flex-basis: 100%;
144144
font-weight: 600;
145145
margin-top: 16px;
146146
margin-bottom: 10px;
147147
position: relative;
148148
}
149-
h3.impl, h3.method, h4.method.trait-impl, h3.type,
150-
h4.type.trait-impl, h4.associatedconstant.trait-impl, h4.associatedtype.trait-impl {
149+
.impl, .method.trait-impl,
150+
.type.trait-impl,
151+
.associatedconstant.trait-impl,
152+
.associatedtype.trait-impl {
151153
padding-left: 15px;
152154
}
153155

156+
div.impl-items > div {
157+
padding-left: 0;
158+
}
159+
154160
h1, h2, h3, h4,
155161
.sidebar, a.source, .search-input, .search-results .result-name,
156162
.content table td:first-child > a,
157-
div.item-list .out-of-band,
163+
div.item-list .out-of-band, span.since,
158164
#source-sidebar, #sidebar-toggle,
159165
details.rustdoc-toggle > summary::before,
160166
details.undocumented > summary::before,
161-
.content ul.crate a.crate,
167+
div.impl-items > div:not(.docblock):not(.item-info),
168+
.content ul.crate a.crate, a.srclink,
162169
/* This selector is for the items listed in the "all items" page. */
163170
#main > ul.docblock > li > a {
164171
font-family: "Fira Sans", Arial, sans-serif;
@@ -313,8 +320,6 @@ nav.sub {
313320
margin-bottom: 14px;
314321
}
315322
.block h2, .block h3 {
316-
margin-top: 0;
317-
margin-bottom: 8px;
318323
text-align: center;
319324
}
320325
.block ul, .block li {
@@ -462,15 +467,7 @@ nav.sub {
462467
font-weight: normal;
463468
}
464469

465-
h3.impl > .out-of-band {
466-
font-size: 21px;
467-
}
468-
469-
h4.method > .out-of-band {
470-
font-size: 19px;
471-
}
472-
473-
h4 > code, h3 > code, .invisible > code {
470+
.method > code, .trait-impl > code, .invisible > code {
474471
max-width: calc(100% - 41px);
475472
display: block;
476473
}
@@ -543,7 +540,7 @@ h4 > code, h3 > code, .invisible > code {
543540
}
544541
.content .multi-column li { width: 100%; display: inline-block; }
545542

546-
.content .method {
543+
.content > .methods > .method {
547544
font-size: 1em;
548545
position: relative;
549546
}
@@ -555,7 +552,7 @@ h4 > code, h3 > code, .invisible > code {
555552
font-size: 0.8em;
556553
}
557554

558-
.content .methods > div:not(.notable-traits):not(.methods) {
555+
.content .methods > div:not(.notable-traits):not(.method) {
559556
margin-left: 40px;
560557
margin-bottom: 15px;
561558
}
@@ -564,9 +561,6 @@ h4 > code, h3 > code, .invisible > code {
564561
margin-left: 20px;
565562
margin-top: -34px;
566563
}
567-
.content .docblock > .impl-items > h4 {
568-
border-bottom: 0;
569-
}
570564
.content .docblock >.impl-items .table-display {
571565
margin: 0;
572566
}
@@ -688,7 +682,8 @@ a {
688682
text-decoration: underline;
689683
}
690684

691-
.invisible > .srclink, h4 > code + .srclink, h3 > code + .srclink {
685+
.invisible > .srclink,
686+
.method > code + .srclink {
692687
position: absolute;
693688
top: 0;
694689
right: 0;
@@ -923,7 +918,7 @@ body.blur > :not(#help) {
923918
flex-grow: 1;
924919
}
925920

926-
.impl-items h4, h4.impl, h3.impl, .methods h3 {
921+
.has-srclink {
927922
display: flex;
928923
flex-basis: 100%;
929924
font-size: 16px;
@@ -1134,6 +1129,13 @@ a.test-arrow:hover{
11341129
margin: 0;
11351130
}
11361131

1132+
.notable-traits .notable {
1133+
margin: 0;
1134+
margin-bottom: 13px;
1135+
font-size: 19px;
1136+
font-weight: 600;
1137+
}
1138+
11371139
.notable-traits .docblock code.content{
11381140
margin: 0;
11391141
padding: 0;
@@ -1197,12 +1199,6 @@ pre.rust {
11971199
margin-left: 5px;
11981200
}
11991201

1200-
h4 > .notable-traits {
1201-
position: absolute;
1202-
left: -44px;
1203-
top: 2px;
1204-
}
1205-
12061202
#all-types {
12071203
text-align: center;
12081204
border: 1px solid;
@@ -1316,14 +1312,6 @@ h4 > .notable-traits {
13161312
border-top: 1px solid;
13171313
}
13181314

1319-
1320-
1321-
h3.notable {
1322-
margin: 0;
1323-
margin-bottom: 13px;
1324-
font-size: 19px;
1325-
}
1326-
13271315
kbd {
13281316
display: inline-block;
13291317
padding: 3px 5px;
@@ -1615,10 +1603,6 @@ details.undocumented[open] > summary::before {
16151603
padding: 0;
16161604
}
16171605

1618-
.content h4 > .out-of-band {
1619-
position: inherit;
1620-
}
1621-
16221606
#search {
16231607
margin-left: 0;
16241608
}
@@ -1638,7 +1622,7 @@ details.undocumented[open] > summary::before {
16381622
z-index: 1;
16391623
}
16401624

1641-
h4 > .notable-traits {
1625+
.notable-traits {
16421626
position: absolute;
16431627
left: -22px;
16441628
top: 24px;

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ body {
1010
color: #c5c5c5;
1111
}
1212

13-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
14-
h4:not(.method):not(.type):not(.tymethod) {
13+
h1, h2, h3, h4 {
1514
color: white;
1615
}
1716
h1.fqn {
@@ -20,10 +19,10 @@ h1.fqn {
2019
h1.fqn a {
2120
color: #fff;
2221
}
23-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod) {
22+
h2, h3, h4 {
2423
border-bottom-color: #5c6773;
2524
}
26-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
25+
h4 {
2726
border: none;
2827
}
2928

@@ -407,6 +406,10 @@ pre.ignore:hover, .information:hover + pre.ignore {
407406
border-color: #5c6773;
408407
}
409408

409+
.notable-traits-tooltiptext .notable {
410+
border-bottom-color: #5c6773;
411+
}
412+
410413
#titles > button.selected {
411414
background-color: #141920 !important;
412415
border-bottom: 1px solid #ffb44c !important;

0 commit comments

Comments
 (0)