Skip to content

Commit 39078aa

Browse files
committed
make item_struct and item_union return impl fmt::Display
1 parent 8e20ca4 commit 39078aa

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
243243
write_str(buf, format_args!("{}", item_function(cx, item, f)))
244244
}
245245
clean::TraitItem(ref t) => write_str(buf, format_args!("{}", item_trait(cx, item, t))),
246-
clean::StructItem(ref s) => item_struct(buf, cx, item, s),
247-
clean::UnionItem(ref s) => item_union(buf, cx, item, s),
246+
clean::StructItem(ref s) => write_str(buf, format_args!("{}", item_struct(cx, item, s))),
247+
clean::UnionItem(ref s) => write_str(buf, format_args!("{}", item_union(cx, item, s))),
248248
clean::EnumItem(ref e) => item_enum(buf, cx, item, e),
249249
clean::TypeAliasItem(ref t) => item_type_alias(buf, cx, item, t),
250250
clean::MacroItem(ref m) => item_macro(buf, cx, item, m),
@@ -1470,7 +1470,11 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
14701470
}
14711471
}
14721472

1473-
fn item_union(w: &mut String, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) {
1473+
fn item_union<'a, 'tcx>(
1474+
cx: &'a Context<'tcx>,
1475+
it: &'a clean::Item,
1476+
s: &'a clean::Union,
1477+
) -> impl fmt::Display + 'a + Captures<'tcx> {
14741478
item_template!(
14751479
#[template(path = "item_union.html")]
14761480
struct ItemUnion<'a, 'cx> {
@@ -1527,7 +1531,10 @@ fn item_union(w: &mut String, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
15271531
}
15281532
}
15291533

1530-
ItemUnion { cx, it, s }.render_into(w).unwrap();
1534+
fmt::from_fn(|w| {
1535+
ItemUnion { cx, it, s }.render_into(w).unwrap();
1536+
Ok(())
1537+
})
15311538
}
15321539

15331540
fn print_tuple_struct_fields<'a, 'cx: 'a>(
@@ -1981,30 +1988,32 @@ fn item_constant(
19811988
write_str(w, format_args!("{}", document(cx, it, None, HeadingOffset::H2)));
19821989
}
19831990

1984-
fn item_struct(w: &mut String, cx: &Context<'_>, it: &clean::Item, s: &clean::Struct) {
1985-
wrap_item(w, |w| {
1986-
render_attributes_in_code(w, it, cx);
1987-
write_str(
1988-
w,
1989-
format_args!(
1991+
fn item_struct<'a, 'tcx>(
1992+
cx: &'a Context<'tcx>,
1993+
it: &'a clean::Item,
1994+
s: &'a clean::Struct,
1995+
) -> impl fmt::Display + 'a + Captures<'tcx> {
1996+
fmt::from_fn(|w| {
1997+
wrap_item(w, |w| {
1998+
render_attributes_in_code(w, it, cx);
1999+
write!(
2000+
w,
19902001
"{}",
19912002
render_struct(it, Some(&s.generics), s.ctor_kind, &s.fields, "", true, cx)
1992-
),
1993-
);
1994-
});
2003+
)
2004+
})?;
19952005

1996-
let def_id = it.item_id.expect_def_id();
2006+
let def_id = it.item_id.expect_def_id();
19972007

1998-
write_str(
1999-
w,
2000-
format_args!(
2008+
write!(
2009+
w,
20012010
"{}{}{}{}",
20022011
document(cx, it, None, HeadingOffset::H2),
20032012
item_fields(cx, it, &s.fields, s.ctor_kind),
20042013
render_assoc_items(cx, it, def_id, AssocItemRender::All),
20052014
document_type_layout(cx, def_id),
2006-
),
2007-
);
2015+
)
2016+
})
20082017
}
20092018

20102019
fn item_fields<'a, 'tcx>(

0 commit comments

Comments
 (0)