Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7872db9

Browse files
committed
make item_trait_alias return impl fmt::Display
1 parent 7a8d26e commit 7872db9

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
266266
),
267267
clean::ForeignTypeItem => write_str(buf, format_args!("{}", item_foreign_type(cx, item))),
268268
clean::KeywordItem => write_str(buf, format_args!("{}", item_keyword(cx, item))),
269-
clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta),
269+
clean::TraitAliasItem(ref ta) => {
270+
write_str(buf, format_args!("{}", item_trait_alias(cx, item, ta)))
271+
}
270272
_ => {
271273
// We don't generate pages for any other type.
272274
unreachable!();
@@ -1244,32 +1246,35 @@ fn item_trait<'a, 'tcx>(
12441246
})
12451247
}
12461248

1247-
fn item_trait_alias(
1248-
w: &mut impl fmt::Write,
1249-
cx: &Context<'_>,
1250-
it: &clean::Item,
1251-
t: &clean::TraitAlias,
1252-
) {
1253-
wrap_item(w, |w| {
1249+
fn item_trait_alias<'a, 'tcx>(
1250+
cx: &'a Context<'tcx>,
1251+
it: &'a clean::Item,
1252+
t: &'a clean::TraitAlias,
1253+
) -> impl fmt::Display + 'a + Captures<'tcx> {
1254+
fmt::from_fn(|w| {
1255+
wrap_item(w, |w| {
1256+
write!(
1257+
w,
1258+
"{attrs}trait {name}{generics}{where_b} = {bounds};",
1259+
attrs = render_attributes_in_pre(it, "", cx),
1260+
name = it.name.unwrap(),
1261+
generics = t.generics.print(cx),
1262+
where_b = print_where_clause(&t.generics, cx, 0, Ending::Newline).maybe_display(),
1263+
bounds = bounds(&t.bounds, true, cx),
1264+
)
1265+
})?;
1266+
1267+
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))?;
1268+
// Render any items associated directly to this alias, as otherwise they
1269+
// won't be visible anywhere in the docs. It would be nice to also show
1270+
// associated items from the aliased type (see discussion in #32077), but
1271+
// we need #14072 to make sense of the generics.
12541272
write!(
12551273
w,
1256-
"{attrs}trait {name}{generics}{where_b} = {bounds};",
1257-
attrs = render_attributes_in_pre(it, "", cx),
1258-
name = it.name.unwrap(),
1259-
generics = t.generics.print(cx),
1260-
where_b = print_where_clause(&t.generics, cx, 0, Ending::Newline).maybe_display(),
1261-
bounds = bounds(&t.bounds, true, cx),
1274+
"{}",
1275+
render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
12621276
)
1263-
.unwrap();
1264-
});
1265-
1266-
write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap();
1267-
// Render any items associated directly to this alias, as otherwise they
1268-
// won't be visible anywhere in the docs. It would be nice to also show
1269-
// associated items from the aliased type (see discussion in #32077), but
1270-
// we need #14072 to make sense of the generics.
1271-
write!(w, "{}", render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All))
1272-
.unwrap();
1277+
})
12731278
}
12741279

12751280
fn item_type_alias<'a, 'tcx>(

0 commit comments

Comments
 (0)