Rollup merge of #112894 - GuillaumeGomez:gui-fields-display, r=notriddle
Fix union fields display  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`
This commit is contained in:
commit
f5470af6a6
7 changed files with 61 additions and 11 deletions
|
@ -421,11 +421,10 @@ fn document<'a, 'cx: 'a>(
|
||||||
display_fn(move |f| {
|
display_fn(move |f| {
|
||||||
document_item_info(cx, item, parent).render_into(f).unwrap();
|
document_item_info(cx, item, parent).render_into(f).unwrap();
|
||||||
if parent.is_none() {
|
if parent.is_none() {
|
||||||
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))?;
|
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{}", document_full(item, cx, heading_offset))?;
|
write!(f, "{}", document_full(item, cx, heading_offset))
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% if !items.is_empty() %}
|
{% if !items.is_empty() %}
|
||||||
<span class="item-info"> {# #}
|
<span class="item-info">
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
{{item|safe}} {# #}
|
{{item|safe}} {# #}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -4,14 +4,15 @@
|
||||||
</code></pre>
|
</code></pre>
|
||||||
{{ self.document() | safe }}
|
{{ self.document() | safe }}
|
||||||
{% if self.fields_iter().peek().is_some() %}
|
{% if self.fields_iter().peek().is_some() %}
|
||||||
<h2 id="fields" class="fields small-section-header">
|
<h2 id="fields" class="fields small-section-header"> {# #}
|
||||||
Fields<a href="#fields" class="anchor">§</a>
|
Fields<a href="#fields" class="anchor">§</a> {# #}
|
||||||
</h2>
|
</h2>
|
||||||
{% for (field, ty) in self.fields_iter() %}
|
{% for (field, ty) in self.fields_iter() %}
|
||||||
{% let name = field.name.expect("union field name") %}
|
{% let name = field.name.expect("union field name") %}
|
||||||
<span id="structfield.{{ name }}" class="{{ ItemType::StructField }} small-section-header">
|
<span id="structfield.{{ name }}" {#+ #}
|
||||||
<a href="#structfield.{{ name }}" class="anchor field">§</a>
|
class="{{ ItemType::StructField +}} small-section-header"> {# #}
|
||||||
<code>{{ name }}: {{ self.print_ty(ty) | safe }}</code>
|
<a href="#structfield.{{ name }}" class="anchor field">§</a> {# #}
|
||||||
|
<code>{{ name }}: {{+ self.print_ty(ty) | safe }}</code> {# #}
|
||||||
</span>
|
</span>
|
||||||
{% if let Some(stability_class) = self.stability_field(field) %}
|
{% if let Some(stability_class) = self.stability_field(field) %}
|
||||||
<span class="stab {{ stability_class }}"></span>
|
<span class="stab {{ stability_class }}"></span>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="main-heading"> {# #}
|
<div class="main-heading"> {# #}
|
||||||
<h1> {# #}
|
<h1>
|
||||||
{{typ}}
|
{{typ}}
|
||||||
{# The breadcrumbs of the item path, like std::string #}
|
{# The breadcrumbs of the item path, like std::string #}
|
||||||
{% for component in path_components %}
|
{% for component in path_components %}
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
alt="Copy item path"> {# #}
|
alt="Copy item path"> {# #}
|
||||||
</button> {# #}
|
</button> {# #}
|
||||||
</h1> {# #}
|
</h1> {# #}
|
||||||
<span class="out-of-band"> {# #}
|
<span class="out-of-band">
|
||||||
{% if !stability_since_raw.is_empty() %}
|
{% if !stability_since_raw.is_empty() %}
|
||||||
{{ stability_since_raw|safe +}} · {#+ #}
|
{{ stability_since_raw|safe +}} · {#+ #}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
18
tests/rustdoc-gui/fields.goml
Normal file
18
tests/rustdoc-gui/fields.goml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// This test checks that fields are displayed as expected (one by line).
|
||||||
|
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/struct.Struct.html"
|
||||||
|
store-position: ("#structfield\.a", {"y": a_y})
|
||||||
|
store-position: ("#structfield\.b", {"y": b_y})
|
||||||
|
assert: |a_y| < |b_y|
|
||||||
|
|
||||||
|
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/union.Union.html"
|
||||||
|
store-position: ("#structfield\.a", {"y": a_y})
|
||||||
|
store-position: ("#structfield\.b", {"y": b_y})
|
||||||
|
assert: |a_y| < |b_y|
|
||||||
|
|
||||||
|
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/enum.Enum.html"
|
||||||
|
store-position: ("#variant\.A\.field\.a", {"y": a_y})
|
||||||
|
store-position: ("#variant\.A\.field\.b", {"y": b_y})
|
||||||
|
assert: |a_y| < |b_y|
|
||||||
|
store-position: ("#variant\.B\.field\.a", {"y": a_y})
|
||||||
|
store-position: ("#variant\.B\.field\.b", {"y": b_y})
|
||||||
|
assert: |a_y| < |b_y|
|
|
@ -486,3 +486,24 @@ pub mod search_results {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod fields {
|
||||||
|
pub struct Struct {
|
||||||
|
pub a: u8,
|
||||||
|
pub b: u32,
|
||||||
|
}
|
||||||
|
pub union Union {
|
||||||
|
pub a: u8,
|
||||||
|
pub b: u32,
|
||||||
|
}
|
||||||
|
pub enum Enum {
|
||||||
|
A {
|
||||||
|
a: u8,
|
||||||
|
b: u32,
|
||||||
|
},
|
||||||
|
B {
|
||||||
|
a: u8,
|
||||||
|
b: u32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
11
tests/rustdoc/union-fields-html.rs
Normal file
11
tests/rustdoc/union-fields-html.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has 'foo/union.Union.html'
|
||||||
|
// Checking that there is a whitespace after `:`.
|
||||||
|
// @has - '//*[@id="structfield.a"]/code' 'a: u8'
|
||||||
|
// @has - '//*[@id="structfield.b"]/code' 'b: u32'
|
||||||
|
pub union Union {
|
||||||
|
pub a: u8,
|
||||||
|
/// tadam
|
||||||
|
pub b: u32,
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue