Skip to content

Commit f5470af

Browse files
Rollup merge of rust-lang#112894 - GuillaumeGomez:gui-fields-display, r=notriddle
Fix union fields display ![Screenshot from 2023-06-21 16-47-24](https://github.com/rust-lang/rust/assets/3050060/833b0fe6-7fb6-4371-86c3-d82fa0c3fe49) So two bugs in this screenshot: no whitespace between field name and type name, both fields are on the same line. Both problems come from issues in the templates because all whitespace are removed if a askama "command" follows. r? `@notriddle`
2 parents d938be1 + 805edb0 commit f5470af

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

src/librustdoc/html/render/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,10 @@ fn document<'a, 'cx: 'a>(
421421
display_fn(move |f| {
422422
document_item_info(cx, item, parent).render_into(f).unwrap();
423423
if parent.is_none() {
424-
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))?;
424+
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))
425425
} else {
426-
write!(f, "{}", document_full(item, cx, heading_offset))?;
426+
write!(f, "{}", document_full(item, cx, heading_offset))
427427
}
428-
Ok(())
429428
})
430429
}
431430

src/librustdoc/html/templates/item_info.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% if !items.is_empty() %}
2-
<span class="item-info"> {# #}
2+
<span class="item-info">
33
{% for item in items %}
44
{{item|safe}} {# #}
55
{% endfor %}

src/librustdoc/html/templates/item_union.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
</code></pre>
55
{{ self.document() | safe }}
66
{% if self.fields_iter().peek().is_some() %}
7-
<h2 id="fields" class="fields small-section-header">
8-
Fields<a href="#fields" class="anchor">§</a>
7+
<h2 id="fields" class="fields small-section-header"> {# #}
8+
Fields<a href="#fields" class="anchor">§</a> {# #}
99
</h2>
1010
{% for (field, ty) in self.fields_iter() %}
1111
{% let name = field.name.expect("union field name") %}
12-
<span id="structfield.{{ name }}" class="{{ ItemType::StructField }} small-section-header">
13-
<a href="#structfield.{{ name }}" class="anchor field">§</a>
14-
<code>{{ name }}: {{ self.print_ty(ty) | safe }}</code>
12+
<span id="structfield.{{ name }}" {#+ #}
13+
class="{{ ItemType::StructField +}} small-section-header"> {# #}
14+
<a href="#structfield.{{ name }}" class="anchor field">§</a> {# #}
15+
<code>{{ name }}: {{+ self.print_ty(ty) | safe }}</code> {# #}
1516
</span>
1617
{% if let Some(stability_class) = self.stability_field(field) %}
1718
<span class="stab {{ stability_class }}"></span>

src/librustdoc/html/templates/print_item.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="main-heading"> {# #}
2-
<h1> {# #}
2+
<h1>
33
{{typ}}
44
{# The breadcrumbs of the item path, like std::string #}
55
{% for component in path_components %}
@@ -12,7 +12,7 @@ <h1> {# #}
1212
alt="Copy item path"> {# #}
1313
</button> {# #}
1414
</h1> {# #}
15-
<span class="out-of-band"> {# #}
15+
<span class="out-of-band">
1616
{% if !stability_since_raw.is_empty() %}
1717
{{ stability_since_raw|safe +}} · {#+ #}
1818
{% endif %}

tests/rustdoc-gui/fields.goml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test checks that fields are displayed as expected (one by line).
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/struct.Struct.html"
3+
store-position: ("#structfield\.a", {"y": a_y})
4+
store-position: ("#structfield\.b", {"y": b_y})
5+
assert: |a_y| < |b_y|
6+
7+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/union.Union.html"
8+
store-position: ("#structfield\.a", {"y": a_y})
9+
store-position: ("#structfield\.b", {"y": b_y})
10+
assert: |a_y| < |b_y|
11+
12+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/enum.Enum.html"
13+
store-position: ("#variant\.A\.field\.a", {"y": a_y})
14+
store-position: ("#variant\.A\.field\.b", {"y": b_y})
15+
assert: |a_y| < |b_y|
16+
store-position: ("#variant\.B\.field\.a", {"y": a_y})
17+
store-position: ("#variant\.B\.field\.b", {"y": b_y})
18+
assert: |a_y| < |b_y|

tests/rustdoc-gui/src/test_docs/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,24 @@ pub mod search_results {
486486
}
487487

488488
}
489+
490+
pub mod fields {
491+
pub struct Struct {
492+
pub a: u8,
493+
pub b: u32,
494+
}
495+
pub union Union {
496+
pub a: u8,
497+
pub b: u32,
498+
}
499+
pub enum Enum {
500+
A {
501+
a: u8,
502+
b: u32,
503+
},
504+
B {
505+
a: u8,
506+
b: u32,
507+
},
508+
}
509+
}

tests/rustdoc/union-fields-html.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name = "foo"]
2+
3+
// @has 'foo/union.Union.html'
4+
// Checking that there is a whitespace after `:`.
5+
// @has - '//*[@id="structfield.a"]/code' 'a: u8'
6+
// @has - '//*[@id="structfield.b"]/code' 'b: u32'
7+
pub union Union {
8+
pub a: u8,
9+
/// tadam
10+
pub b: u32,
11+
}

0 commit comments

Comments
 (0)