Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: migrate item_struct to an Askama template #111430

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
16 changes: 11 additions & 5 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ fn assoc_method(
write!(w, "{}", render_attributes_in_pre(meth, indent_str, cx));
(4, indent_str, Ending::NoNewline)
} else {
render_attributes_in_code(w, meth, cx);
write!(w, "{}", render_attributes_in_code(meth, tcx));
(0, "", Ending::Newline)
};
w.reserve(header_len + "<a href=\"\" class=\"fn\">{".len() + "</a>".len());
Expand Down Expand Up @@ -1075,10 +1075,16 @@ fn render_attributes_in_pre<'a, 'tcx: 'a>(

// When an attribute is rendered inside a <code> tag, it is formatted using
// a div to produce a newline after it.
fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, cx: &Context<'_>) {
for attr in it.attributes(cx.tcx(), cx.cache(), false) {
write!(w, "<div class=\"code-attribute\">{attr}</div>").unwrap();
}
fn render_attributes_in_code<'a, 'tcx>(
it: &'a clean::Item,
tcx: TyCtxt<'tcx>,
) -> impl fmt::Display + Captures<'a> + Captures<'tcx> {
display_fn(move |f| {
for a in it.attributes(tcx, false) {
write!(f, "<div class=\"code-attribute\">{}</div>", a)?;
}
Ok(())
})
}

#[derive(Copy, Clone)]
Expand Down
Loading
Loading