Skip to content

Commit 1644d5d

Browse files
committed
make item_static return impl fmt::Display
1 parent 877e775 commit 1644d5d

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,12 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
254254
write_str(buf, format_args!("{}", item_proc_macro(cx, item, m)))
255255
}
256256
clean::PrimitiveItem(_) => write_str(buf, format_args!("{}", item_primitive(cx, item))),
257-
clean::StaticItem(ref i) => item_static(buf, cx, item, i, None),
258-
clean::ForeignStaticItem(ref i, safety) => item_static(buf, cx, item, i, Some(*safety)),
257+
clean::StaticItem(ref i) => {
258+
write_str(buf, format_args!("{}", item_static(cx, item, i, None)))
259+
}
260+
clean::ForeignStaticItem(ref i, safety) => {
261+
write_str(buf, format_args!("{}", item_static(cx, item, i, Some(*safety))))
262+
}
259263
clean::ConstantItem(ci) => item_constant(buf, cx, item, &ci.generics, &ci.type_, &ci.kind),
260264
clean::ForeignTypeItem => item_foreign_type(buf, cx, item),
261265
clean::KeywordItem => item_keyword(buf, cx, item),
@@ -2091,28 +2095,28 @@ fn item_fields<'a, 'tcx>(
20912095
})
20922096
}
20932097

2094-
fn item_static(
2095-
w: &mut impl fmt::Write,
2096-
cx: &Context<'_>,
2097-
it: &clean::Item,
2098-
s: &clean::Static,
2098+
fn item_static<'a, 'tcx>(
2099+
cx: &'a Context<'tcx>,
2100+
it: &'a clean::Item,
2101+
s: &'a clean::Static,
20992102
safety: Option<hir::Safety>,
2100-
) {
2101-
wrap_item(w, |buffer| {
2102-
render_attributes_in_code(buffer, it, cx);
2103-
write!(
2104-
buffer,
2105-
"{vis}{safe}static {mutability}{name}: {typ}",
2106-
vis = visibility_print_with_space(it, cx),
2107-
safe = safety.map(|safe| safe.prefix_str()).unwrap_or(""),
2108-
mutability = s.mutability.print_with_space(),
2109-
name = it.name.unwrap(),
2110-
typ = s.type_.print(cx)
2111-
)
2112-
.unwrap();
2113-
});
2103+
) -> impl fmt::Display + 'a + Captures<'tcx> {
2104+
fmt::from_fn(move |w| {
2105+
wrap_item(w, |w| {
2106+
render_attributes_in_code(w, it, cx);
2107+
write!(
2108+
w,
2109+
"{vis}{safe}static {mutability}{name}: {typ}",
2110+
vis = visibility_print_with_space(it, cx),
2111+
safe = safety.map(|safe| safe.prefix_str()).unwrap_or(""),
2112+
mutability = s.mutability.print_with_space(),
2113+
name = it.name.unwrap(),
2114+
typ = s.type_.print(cx)
2115+
)
2116+
})?;
21142117

2115-
write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap();
2118+
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
2119+
})
21162120
}
21172121

21182122
fn item_foreign_type(w: &mut impl fmt::Write, cx: &Context<'_>, it: &clean::Item) {

0 commit comments

Comments
 (0)