Skip to content

Commit 96628f4

Browse files
Rollup merge of #123706 - notriddle:notriddle/html-cleanup, r=GuillaumeGomez
rustdoc: reduce per-page HTML overhead r? `@GuillaumeGomez`
2 parents 7a29d39 + 3a007db commit 96628f4

12 files changed

+48
-55
lines changed

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'tcx> Context<'tcx> {
231231
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
232232
};
233233
let mut page_buffer = Buffer::html();
234-
print_item(self, it, &mut page_buffer, &page);
234+
print_item(self, it, &mut page_buffer);
235235
layout::render(
236236
&clone_shared.layout,
237237
&page,

src/librustdoc/html/render/print_item.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ use crate::html::format::{
3131
display_fn, join_with_double_colon, print_abi_with_space, print_constness_with_space,
3232
print_where_clause, visibility_print_with_space, Buffer, Ending, PrintWithSpace,
3333
};
34-
use crate::html::layout::Page;
34+
use crate::html::highlight;
3535
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3636
use crate::html::render::{document_full, document_item_info};
3737
use crate::html::url_parts_builder::UrlPartsBuilder;
38-
use crate::html::{highlight, static_files};
3938

4039
use askama::Template;
4140
use itertools::Itertools;
@@ -157,8 +156,6 @@ struct PathComponent {
157156
#[derive(Template)]
158157
#[template(path = "print_item.html")]
159158
struct ItemVars<'a> {
160-
static_root_path: &'a str,
161-
clipboard_svg: &'static static_files::StaticFile,
162159
typ: &'a str,
163160
name: &'a str,
164161
item_type: &'a str,
@@ -178,12 +175,7 @@ fn print_where_clause_and_check<'a, 'tcx: 'a>(
178175
len_before != buffer.len()
179176
}
180177

181-
pub(super) fn print_item(
182-
cx: &mut Context<'_>,
183-
item: &clean::Item,
184-
buf: &mut Buffer,
185-
page: &Page<'_>,
186-
) {
178+
pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buffer) {
187179
debug_assert!(!item.is_stripped());
188180
let typ = match *item.kind {
189181
clean::ModuleItem(_) => {
@@ -252,8 +244,6 @@ pub(super) fn print_item(
252244
};
253245

254246
let item_vars = ItemVars {
255-
static_root_path: &page.get_static_root_path(),
256-
clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
257247
typ,
258248
name: item.name.as_ref().unwrap().as_str(),
259249
item_type: &item.type_().to_string(),
@@ -1237,22 +1227,18 @@ fn item_opaque_ty(
12371227
}
12381228

12391229
fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
1240-
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
1241-
wrap_item(w, |w| {
1242-
write!(
1243-
w,
1244-
"{attrs}{vis}type {name}{generics}{where_clause} = {type_};",
1245-
attrs = render_attributes_in_pre(it, "", cx),
1246-
vis = visibility_print_with_space(it, cx),
1247-
name = it.name.unwrap(),
1248-
generics = t.generics.print(cx),
1249-
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
1250-
type_ = t.type_.print(cx),
1251-
);
1252-
});
1253-
}
1254-
1255-
write_content(w, cx, it, t);
1230+
wrap_item(w, |w| {
1231+
write!(
1232+
w,
1233+
"{attrs}{vis}type {name}{generics}{where_clause} = {type_};",
1234+
attrs = render_attributes_in_pre(it, "", cx),
1235+
vis = visibility_print_with_space(it, cx),
1236+
name = it.name.unwrap(),
1237+
generics = t.generics.print(cx),
1238+
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
1239+
type_ = t.type_.print(cx),
1240+
);
1241+
});
12561242

12571243
write!(w, "{}", document(cx, it, None, HeadingOffset::H2));
12581244

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,16 @@ a.tooltip:hover::after {
16031603
border-color: var(--settings-button-border-focus);
16041604
}
16051605

1606+
#settings-menu > a {
1607+
line-height: 0;
1608+
font-size: 0;
1609+
}
1610+
#settings-menu > a:before {
1611+
content: url('wheel-63255fc4502dca9a.svg');
1612+
width: 22px;
1613+
height: 22px;
1614+
}
1615+
16061616
#sidebar-button > a:before {
16071617
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" \
16081618
fill="none" stroke="black">\
@@ -1622,11 +1632,17 @@ a.tooltip:hover::after {
16221632
padding-left: 2px;
16231633
border: 0;
16241634
width: 33px;
1635+
line-height: 0;
1636+
font-size: 0;
16251637
}
1626-
#copy-path > img {
1638+
1639+
#copy-path:before {
16271640
filter: var(--copy-path-img-filter);
1641+
content: url('clipboard-24048e6d87f63d07.svg');
1642+
width: 19px;
1643+
height: 18px;
16281644
}
1629-
#copy-path:hover > img {
1645+
#copy-path:hover:before {
16301646
filter: var(--copy-path-img-hover-filter);
16311647
}
16321648

Loading
-715 Bytes
Binary file not shown.
+1-1
Loading

src/librustdoc/html/static_files.rs

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ static_files! {
106106
license_mit => "static/LICENSE-MIT.txt",
107107
rust_logo_svg => "static/images/rust-logo.svg",
108108
rust_favicon_svg => "static/images/favicon.svg",
109-
rust_favicon_png_16 => "static/images/favicon-16x16.png",
110109
rust_favicon_png_32 => "static/images/favicon-32x32.png",
111110
fira_sans_regular => "static/fonts/FiraSans-Regular.woff2",
112111
fira_sans_medium => "static/fonts/FiraSans-Medium.woff2",

src/librustdoc/html/templates/page.html

+7-13
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
<meta name="generator" content="rustdoc"> {# #}
77
<meta name="description" content="{{page.description}}"> {# #}
88
<title>{{page.title}}</title> {# #}
9-
<script> if (window.location.protocol !== "file:") document.write(` {# Hack to skip preloading fonts locally - see #98769 #}
10-
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}{{files.source_serif_4_regular}}"> {# #}
11-
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}{{files.fira_sans_regular}}"> {# #}
12-
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}{{files.fira_sans_medium}}"> {# #}
13-
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}{{files.source_code_pro_regular}}"> {# #}
14-
<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}{{files.source_code_pro_semibold}}"> {# #}
15-
`)</script> {# #}
9+
<script>if(window.location.protocol!=="file:") {# Hack to skip preloading fonts locally - see #98769 #}
10+
for(f of "{{files.source_serif_4_regular}},{{files.fira_sans_regular}},{{files.fira_sans_medium}},{{files.source_code_pro_regular}},{{files.source_code_pro_semibold}}".split(",")) {# #}
11+
document.write(`<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}${f}">`) {# #}
12+
</script> {# #}
1613
<link rel="stylesheet" {#+ #}
1714
href="{{static_root_path|safe}}{{files.normalize_css}}"> {# #}
1815
<link rel="stylesheet" {#+ #}
@@ -61,8 +58,6 @@
6158
{% if !layout.favicon.is_empty() %}
6259
<link rel="icon" href="{{layout.favicon}}"> {# #}
6360
{% else %}
64-
<link rel="alternate icon" type="image/png" {#+ #}
65-
href="{{static_root_path|safe}}{{files.rust_favicon_png_16}}"> {# #}
6661
<link rel="alternate icon" type="image/png" {#+ #}
6762
href="{{static_root_path|safe}}{{files.rust_favicon_png_32}}"> {# #}
6863
<link rel="icon" type="image/svg+xml" {#+ #}
@@ -114,13 +109,13 @@ <h2> {# #}
114109
<div class="version">{{+ display_krate_version_extra}}</div> {# #}
115110
{% endif %}
116111
{% else %}
117-
<div class="src-sidebar-title">
112+
<div class="src-sidebar-title"> {# #}
118113
<h2>Files</h2> {# #}
119114
</div> {# #}
120115
{% endif %}
121116
{{ sidebar|safe }}
122117
</nav> {# #}
123-
<div class="sidebar-resizer"></div>
118+
<div class="sidebar-resizer"></div> {# #}
124119
<main> {# #}
125120
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
126121
<nav class="sub"> {# #}
@@ -142,8 +137,7 @@ <h2>Files</h2> {# #}
142137
</div> {# #}
143138
<div id="settings-menu" tabindex="-1"> {# #}
144139
<a href="{{page.root_path|safe}}settings.html" title="settings"> {# #}
145-
<img width="22" height="22" alt="Change settings" {#+ #}
146-
src="{{static_root_path|safe}}{{files.wheel_svg}}"> {# #}
140+
Settings {# #}
147141
</a> {# #}
148142
</div> {# #}
149143
</form> {# #}

src/librustdoc/html/templates/print_item.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ <h1>
77
{% endfor %}
88
<a class="{{item_type}}" href="#">{{name}}</a> {# #}
99
<button id="copy-path" title="Copy item path to clipboard"> {# #}
10-
<img src="{{static_root_path|safe}}{{clipboard_svg}}" {#+ #}
11-
width="19" height="18" {#+ #}
12-
alt="Copy item path"> {# #}
10+
Copy item path {# #}
1311
</button> {# #}
1412
</h1> {# #}
1513
<span class="out-of-band">

src/librustdoc/html/templates/sidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h2 class="location"> {# #}
55
{% endif %}
66
<div class="sidebar-elems">
77
{% if is_crate %}
8-
<ul class="block">
8+
<ul class="block"> {# #}
99
<li><a id="all-types" href="all.html">All Items</a></li> {# #}
1010
</ul>
1111
{% endif %}

tests/rustdoc-gui/search-result-go-to-first.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
// First, we check that the first page doesn't have the string we're looking for to ensure
44
// that the feature is changing page as expected.
55
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
6-
assert-text-false: (".main-heading h1", "Struct test_docs::Foo")
6+
assert-text-false: (".main-heading h1", "Struct test_docs::FooCopy item path")
77

88
// We now check that we land on the search result page if "go_to_first" isn't set.
99
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo"
1010
// Waiting for the search results to appear...
1111
wait-for: "#search-tabs"
12-
assert-text-false: (".main-heading h1", "Struct test_docs::Foo")
12+
assert-text-false: (".main-heading h1", "Struct test_docs::FooCopy item path")
1313
// Ensure that the search results are displayed, not the "normal" content.
1414
assert-css: ("#main-content", {"display": "none"})
1515

1616
// Now we can check that the feature is working as expected!
1717
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo&go_to_first=true"
1818
// Waiting for the page to load...
19-
wait-for-text: (".main-heading h1", "Struct test_docs::Foo")
19+
wait-for-text: (".main-heading h1", "Struct test_docs::FooCopy item path")

tests/rustdoc-gui/toggle-click-deadspace.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ assert-attribute-false: (".impl-items .toggle", {"open": ""})
1212

1313
// Click the "Trait" part of "impl Trait" and verify it navigates.
1414
click: "#impl-Trait-for-Foo h3 a:first-of-type"
15-
assert-text: (".main-heading h1", "Trait lib2::Trait")
15+
assert-text: (".main-heading h1", "Trait lib2::TraitCopy item path")

0 commit comments

Comments
 (0)