Skip to content

Commit 5f9746b

Browse files
committed
rustdoc: use a separate template for type layout size
1 parent 08f204e commit 5f9746b

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/librustdoc/html/render/print_item.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,14 @@ fn document_type_layout<'a, 'cx: 'a>(
19451945
ty_def_id: DefId,
19461946
}
19471947

1948+
#[derive(Template)]
1949+
#[template(path = "type_layout_size.html")]
1950+
struct TypeLayoutSize {
1951+
is_unsized: bool,
1952+
is_uninhabited: bool,
1953+
size: u64,
1954+
}
1955+
19481956
impl<'a, 'cx: 'a> TypeLayout<'a, 'cx> {
19491957
fn variants<'b: 'a>(&'b self) -> Option<&'b IndexVec<VariantIdx, LayoutS>> {
19501958
if let Variants::Multiple { variants, .. } =
@@ -1986,18 +1994,10 @@ fn document_type_layout<'a, 'cx: 'a>(
19861994
tag_size: u64,
19871995
) -> impl fmt::Display + Captures<'cx> + Captures<'b> {
19881996
display_fn(move |f| {
1989-
if layout.abi.is_unsized() {
1990-
write!(f, "(unsized)")?;
1991-
} else {
1992-
let size = layout.size.bytes() - tag_size;
1993-
write!(f, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" })?;
1994-
if layout.abi.is_uninhabited() {
1995-
write!(
1996-
f,
1997-
" (<a href=\"https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited\">uninhabited</a>)"
1998-
)?;
1999-
}
2000-
}
1997+
let is_unsized = layout.abi.is_unsized();
1998+
let is_uninhabited = layout.abi.is_uninhabited();
1999+
let size = layout.size.bytes() - tag_size;
2000+
TypeLayoutSize { is_unsized, is_uninhabited, size }.render_into(f).unwrap();
20012001
Ok(())
20022002
})
20032003
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% if is_unsized %}
2+
(unsized)
3+
{% else %}
4+
{% if size == 1 %}
5+
1 byte
6+
{% else %}
7+
{{ size +}} bytes
8+
{% endif %}
9+
{% if is_uninhabited %}
10+
{# +#} (<a href="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited">uninhabited</a>)
11+
{% endif %}
12+
{% endif %}

0 commit comments

Comments
 (0)