Skip to content

Commit 5b77342

Browse files
authored
Unrolled build for rust-lang#130706
Rollup merge of rust-lang#130706 - GuillaumeGomez:remove-unneeded-jinja-comments, r=notriddle [rustdoc] Remove unneeded jinja comments This is a follow-up of rust-lang#130585. Since we now check for the jinja comments we missed, we can now check for the jinja comments which are unneeded. It will make the parsing and therefore the compilation a tiny bit faster (well, if anyone sees a difference haha). The real goal is mostly to have easier to read template files. 😉 r? ``@notriddle``
2 parents 58420a0 + 575df06 commit 5b77342

File tree

8 files changed

+83
-51
lines changed

8 files changed

+83
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% if !items.is_empty() %}
22
<span class="item-info">
33
{% for item in items %}
4-
{{item|safe}} {# #}
4+
{{item|safe}}
55
{% endfor %}
66
</span>
77
{% endif %}

src/librustdoc/html/templates/page.html

+31-31
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
<link rel="stylesheet" {#+ #}
1313
href="{{static_root_path|safe}}{{files.normalize_css}}"> {# #}
1414
<link rel="stylesheet" {#+ #}
15-
href="{{static_root_path|safe}}{{files.rustdoc_css}}"> {# #}
15+
href="{{static_root_path|safe}}{{files.rustdoc_css}}">
1616
{% if !layout.default_settings.is_empty() %}
1717
<script id="default-settings" {#+ #}
1818
{%~ for (k, v) in layout.default_settings ~%}
1919
data-{{k}}="{{v}}"
2020
{% endfor %}
21-
></script> {# #}
21+
></script>
2222
{% endif %}
2323
<meta name="rustdoc-vars" {#+ #}
2424
data-root-path="{{page.root_path|safe}}" {#+ #}
@@ -31,36 +31,36 @@
3131
data-search-js="{{files.search_js}}" {#+ #}
3232
data-settings-js="{{files.settings_js}}" {#+ #}
3333
> {# #}
34-
<script src="{{static_root_path|safe}}{{files.storage_js}}"></script> {# #}
34+
<script src="{{static_root_path|safe}}{{files.storage_js}}"></script>
3535
{% if page.css_class.contains("crate") %}
36-
<script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #}
36+
<script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script>
3737
{% else if page.css_class == "src" %}
3838
<script defer src="{{static_root_path|safe}}{{files.src_script_js}}"></script> {# #}
39-
<script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script> {# #}
39+
<script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script>
4040
{% else if !page.css_class.contains("mod") %}
41-
<script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #}
41+
<script defer src="sidebar-items{{page.resource_suffix}}.js"></script>
4242
{% else if !page.css_class.contains("sys") %}
43-
<script defer src="../sidebar-items{{page.resource_suffix}}.js"></script> {# #}
43+
<script defer src="../sidebar-items{{page.resource_suffix}}.js"></script>
4444
{% endif %}
45-
<script defer src="{{static_root_path|safe}}{{files.main_js}}"></script> {# #}
45+
<script defer src="{{static_root_path|safe}}{{files.main_js}}"></script>
4646
{% if layout.scrape_examples_extension %}
47-
<script defer src="{{static_root_path|safe}}{{files.scrape_examples_js}}"></script> {# #}
47+
<script defer src="{{static_root_path|safe}}{{files.scrape_examples_js}}"></script>
4848
{% endif %}
4949
<noscript> {# #}
5050
<link rel="stylesheet" {#+ #}
5151
href="{{static_root_path|safe}}{{files.noscript_css}}"> {# #}
52-
</noscript> {# #}
52+
</noscript>
5353
{% if layout.css_file_extension.is_some() %}
5454
<link rel="stylesheet" {#+ #}
55-
href="{{page.root_path|safe}}theme{{page.resource_suffix}}.css"> {# #}
55+
href="{{page.root_path|safe}}theme{{page.resource_suffix}}.css">
5656
{% endif %}
5757
{% if !layout.favicon.is_empty() %}
58-
<link rel="icon" href="{{layout.favicon}}"> {# #}
58+
<link rel="icon" href="{{layout.favicon}}">
5959
{% else %}
6060
<link rel="alternate icon" type="image/png" {#+ #}
6161
href="{{static_root_path|safe}}{{files.rust_favicon_png_32}}"> {# #}
6262
<link rel="icon" type="image/svg+xml" {#+ #}
63-
href="{{static_root_path|safe}}{{files.rust_favicon_svg}}"> {# #}
63+
href="{{static_root_path|safe}}{{files.rust_favicon_svg}}">
6464
{% endif %}
6565
{{ layout.external_html.in_header|safe }}
6666
</head> {# #}
@@ -69,60 +69,60 @@
6969
<div class="warning"> {# #}
7070
This old browser is unsupported and will most likely display funky things. {# #}
7171
</div> {# #}
72-
<![endif]--> {# #}
72+
<![endif]-->
7373
{{ layout.external_html.before_content|safe }}
7474
{% if page.css_class != "src" %}
7575
<nav class="mobile-topbar"> {# #}
76-
<button class="sidebar-menu-toggle" title="show sidebar"></button> {# #}
76+
<button class="sidebar-menu-toggle" title="show sidebar"></button>
7777
{% if !layout.logo.is_empty() || page.rust_logo %}
78-
<a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html"> {# #}
78+
<a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">
7979
{% if page.rust_logo %}
80-
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt=""> {# #}
80+
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="">
8181
{% else if !layout.logo.is_empty() %}
82-
<img src="{{layout.logo}}" alt=""> {# #}
82+
<img src="{{layout.logo}}" alt="">
8383
{% endif %}
84-
</a> {# #}
84+
</a>
8585
{% endif %}
8686
</nav>
8787
{% endif %}
88-
<nav class="sidebar"> {# #}
88+
<nav class="sidebar">
8989
{% if page.css_class != "src" %}
9090
<div class="sidebar-crate">
9191
{% if !layout.logo.is_empty() || page.rust_logo %}
92-
<a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html"> {# #}
92+
<a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">
9393
{% if page.rust_logo %}
94-
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo"> {# #}
94+
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo">
9595
{% else if !layout.logo.is_empty() %}
96-
<img src="{{layout.logo}}" alt="logo"> {# #}
96+
<img src="{{layout.logo}}" alt="logo">
9797
{% endif %}
98-
</a> {# #}
98+
</a>
9999
{% endif %}
100100
<h2> {# #}
101-
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate|wrapped|safe}}</a> {# #}
101+
<a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate|wrapped|safe}}</a>
102102
{% if !display_krate_version_number.is_empty() %}
103103
<span class="version">{{+ display_krate_version_number}}</span>
104104
{% endif %}
105105
</h2> {# #}
106-
</div> {# #}
106+
</div>
107107
{% if !display_krate_version_extra.is_empty() %}
108-
<div class="version">{{+ display_krate_version_extra}}</div> {# #}
108+
<div class="version">{{+ display_krate_version_extra}}</div>
109109
{% endif %}
110110
{% else %}
111111
<div class="src-sidebar-title"> {# #}
112112
<h2>Files</h2> {# #}
113-
</div> {# #}
113+
</div>
114114
{% endif %}
115115
{{ sidebar|safe }}
116116
</nav> {# #}
117117
<div class="sidebar-resizer"></div> {# #}
118-
<main> {# #}
118+
<main>
119119
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
120120
{# defined in storage.js to avoid duplicating complex UI across every page #}
121121
{# and because the search form only works if JS is enabled anyway #}
122122
<rustdoc-search></rustdoc-search> {# #}
123-
<section id="main-content" class="content">{{ content|safe }}</section> {# #}
123+
<section id="main-content" class="content">{{ content|safe }}</section>
124124
{% if page.css_class != "src" %}</div>{% endif %}
125-
</main> {# #}
125+
</main>
126126
{{ layout.external_html.after_content|safe }}
127127
</body> {# #}
128128
</html> {# #}

src/librustdoc/html/templates/print_item.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="main-heading"> {# #}
1+
<div class="main-heading">
22
{% if !path_components.is_empty() %}
33
<span class="rustdoc-breadcrumbs">
44
{% for (i, component) in path_components.iter().enumerate() %}

src/librustdoc/html/templates/short_item_info.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
<div class="stab deprecated"> {# #}
44
<span class="emoji">👎</span> {# #}
55
<span>{{message|safe}}</span> {# #}
6-
</div> {# #}
6+
</div>
77
{% when Self::Unstable with { feature, tracking } %}
88
<div class="stab unstable"> {# #}
99
<span class="emoji">🔬</span> {# #}
1010
<span> {# #}
1111
This is a nightly-only experimental API. ({# #}
12-
<code>{{feature}}</code> {# #}
12+
<code>{{feature}}</code>
1313
{% match tracking %}
1414
{% when Some with ((url, num)) %}
15-
&nbsp;<a href="{{url}}{{num}}">#{{num}}</a> {# #}
15+
&nbsp;<a href="{{url}}{{num}}">#{{num}}</a>
1616
{% when None %}
1717
{% endmatch %}
1818
) {# #}
1919
</span> {# #}
20-
</div> {# #}
20+
</div>
2121
{% when Self::Portability with { message } %}
22-
<div class="stab portability">{{message|safe}}</div> {# #}
22+
<div class="stab portability">{{message|safe}}</div>
2323
{% endmatch %}

src/librustdoc/html/templates/sidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h3> {# #}
3030
{% else %}
3131
{{link.name}}
3232
{% endmatch %}
33-
</a> {# #}
33+
</a>
3434
{% if !link.children.is_empty() %}
3535
<ul>
3636
{% for child in link.children %}

src/librustdoc/html/templates/source.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1> {# #}
99
</div>
1010
{% else %}
1111
{% endmatch %}
12-
<div class="example-wrap"> {# #}
12+
<div class="example-wrap">
1313
{# https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr
1414
Do not show "1 2 3 4 5 ..." in web search results. #}
1515
<div data-nosnippet><pre class="src-line-numbers">
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h2 id="layout" class="section-header"> {# #}
22
Layout<a href="#layout" class="anchor">§</a> {# #}
33
</h2> {# #}
4-
<div class="docblock"> {# #}
4+
<div class="docblock">
55
{% match type_layout_size %}
66
{% when Ok(type_layout_size) %}
77
<div class="warning"> {# #}
@@ -14,19 +14,19 @@ <h2 id="layout" class="section-header"> {# #}
1414
chapter for details on type layout guarantees. {# #}
1515
</p> {# #}
1616
</div> {# #}
17-
<p><strong>Size:</strong> {{+ type_layout_size|safe }}</p> {# #}
17+
<p><strong>Size:</strong> {{+ type_layout_size|safe }}</p>
1818
{% if !variants.is_empty() %}
1919
<p> {# #}
2020
<strong>Size for each variant:</strong> {# #}
2121
</p> {# #}
22-
<ul> {# #}
22+
<ul>
2323
{% for (name, layout_size) in variants %}
2424
<li> {# #}
2525
<code>{{ name }}</code>: {#+ #}
2626
{{ layout_size|safe }}
27-
</li> {# #}
27+
</li>
2828
{% endfor %}
29-
</ul> {# #}
29+
</ul>
3030
{% endif %}
3131
{# This kind of layout error can occur with valid code, e.g. if you try to
3232
get the layout of a generic type such as `Vec<T>`. #}
@@ -35,29 +35,29 @@ <h2 id="layout" class="section-header"> {# #}
3535
<strong>Note:</strong> Unable to compute type layout, {#+ #}
3636
possibly due to this type having generic parameters. {#+ #}
3737
Layout can only be computed for concrete, fully-instantiated types. {# #}
38-
</p> {# #}
38+
</p>
3939
{# This kind of error probably can't happen with valid code, but we don't
4040
want to panic and prevent the docs from building, so we just let the
4141
user know that we couldn't compute the layout. #}
4242
{% when Err(LayoutError::SizeOverflow(_)) %}
4343
<p> {# #}
4444
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
4545
the type was too big. {# #}
46-
</p> {# #}
46+
</p>
4747
{% when Err(LayoutError::ReferencesError(_)) %}
4848
<p> {# #}
4949
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
5050
the type references errors. {# #}
51-
</p> {# #}
51+
</p>
5252
{% when Err(LayoutError::NormalizationFailure(_, _)) %}
5353
<p> {# #}
5454
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
5555
the type failed to be normalized. {# #}
56-
</p> {# #}
56+
</p>
5757
{% when Err(LayoutError::Cycle(_)) %}
5858
<p> {# #}
5959
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
6060
the type's layout depended on the type's layout itself. {# #}
61-
</p> {# #}
61+
</p>
6262
{% endmatch %}
6363
</div> {# #}

src/tools/tidy/src/rustdoc_templates.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,39 @@ pub fn check(librustdoc_path: &Path, bad: &mut bool) {
2020

2121
while let Some((pos, line)) = lines.next() {
2222
let line = line.trim();
23-
if TAGS.iter().any(|(_, tag)| line.ends_with(tag)) {
23+
if let Some(need_next_line_check) = TAGS.iter().find_map(|(tag, end_tag)| {
24+
// We first check if the line ends with a jinja tag.
25+
if !line.ends_with(end_tag) {
26+
return None;
27+
// Then we check if this a comment tag.
28+
} else if *tag != "{#" {
29+
return Some(false);
30+
// And finally we check if the comment is empty (ie, only there to strip
31+
// extra whitespace characters).
32+
} else if let Some(start_pos) = line.rfind(tag) {
33+
Some(line[start_pos + 2..].trim() == "#}")
34+
} else {
35+
Some(false)
36+
}
37+
}) {
38+
// All good, the line is ending is a jinja tag. But maybe this tag is useless
39+
// if the next line starts with a jinja tag as well!
40+
//
41+
// However, only (empty) comment jinja tags are concerned about it.
42+
if need_next_line_check
43+
&& lines.peek().is_some_and(|(_, next_line)| {
44+
let next_line = next_line.trim_start();
45+
TAGS.iter().any(|(tag, _)| next_line.starts_with(tag))
46+
})
47+
{
48+
// It seems like ending this line with a jinja tag is not needed after all.
49+
tidy_error!(
50+
bad,
51+
"`{}` at line {}: unneeded `{{# #}}` tag at the end of the line",
52+
path.path().display(),
53+
pos + 1,
54+
);
55+
}
2456
continue;
2557
}
2658
let Some(next_line) = lines.peek().map(|(_, next_line)| next_line.trim()) else {

0 commit comments

Comments
 (0)