Skip to content

Commit e9d2de6

Browse files
committed
make render_struct return impl fmt::Display
1 parent 2014fdf commit e9d2de6

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,13 @@ fn render_enum_fields(
16981698
);
16991699
}
17001700
clean::VariantKind::Struct(ref s) => {
1701-
render_struct(w, v, None, None, &s.fields, TAB, false, cx);
1701+
write_str(
1702+
w,
1703+
format_args!(
1704+
"{}",
1705+
render_struct(v, None, None, &s.fields, TAB, false, cx)
1706+
),
1707+
);
17021708
}
17031709
},
17041710
_ => unreachable!(),
@@ -1978,7 +1984,13 @@ fn item_constant(
19781984
fn item_struct(w: &mut String, cx: &Context<'_>, it: &clean::Item, s: &clean::Struct) {
19791985
wrap_item(w, |w| {
19801986
render_attributes_in_code(w, it, cx);
1981-
render_struct(w, it, Some(&s.generics), s.ctor_kind, &s.fields, "", true, cx);
1987+
write_str(
1988+
w,
1989+
format_args!(
1990+
"{}",
1991+
render_struct(it, Some(&s.generics), s.ctor_kind, &s.fields, "", true, cx)
1992+
),
1993+
);
19821994
});
19831995

19841996
write_str(w, format_args!("{}", document(cx, it, None, HeadingOffset::H2)));
@@ -2349,31 +2361,28 @@ fn render_union<'a, 'cx: 'a>(
23492361
})
23502362
}
23512363

2352-
fn render_struct(
2353-
w: &mut String,
2354-
it: &clean::Item,
2355-
g: Option<&clean::Generics>,
2364+
fn render_struct<'a, 'tcx>(
2365+
it: &'a clean::Item,
2366+
g: Option<&'a clean::Generics>,
23562367
ty: Option<CtorKind>,
2357-
fields: &[clean::Item],
2358-
tab: &str,
2368+
fields: &'a [clean::Item],
2369+
tab: &'a str,
23592370
structhead: bool,
2360-
cx: &Context<'_>,
2361-
) {
2362-
write_str(
2363-
w,
2364-
format_args!(
2371+
cx: &'a Context<'tcx>,
2372+
) -> impl fmt::Display + 'a + Captures<'tcx> {
2373+
fmt::from_fn(move |w| {
2374+
write!(
2375+
w,
23652376
"{}{}{}",
23662377
visibility_print_with_space(it, cx),
23672378
if structhead { "struct " } else { "" },
23682379
it.name.unwrap()
2369-
),
2370-
);
2371-
if let Some(g) = g {
2372-
write_str(w, format_args!("{}", g.print(cx)));
2373-
}
2374-
write_str(
2375-
w,
2376-
format_args!(
2380+
)?;
2381+
if let Some(g) = g {
2382+
write!(w, "{}", g.print(cx))?;
2383+
}
2384+
write!(
2385+
w,
23772386
"{}",
23782387
render_struct_fields(
23792388
g,
@@ -2384,8 +2393,8 @@ fn render_struct(
23842393
it.has_stripped_entries().unwrap_or(false),
23852394
cx,
23862395
)
2387-
),
2388-
);
2396+
)
2397+
})
23892398
}
23902399

23912400
fn render_struct_fields<'a, 'tcx>(

0 commit comments

Comments
 (0)