Skip to content

Commit

Permalink
Rollup merge of #112031 - sladyn98:migrate-proc-macro, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Migrate  `item_proc_macro` to Askama

This PR migrates `item_proc_macro` to Askama

Refers #108868
  • Loading branch information
matthiaskrgr committed May 31, 2023
2 parents e6e4f7e + 5c780d9 commit fdd62cf
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,30 +1420,36 @@ fn item_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
}

fn item_proc_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
wrap_item(w, |w| {
fn item_proc_macro(
w: &mut impl fmt::Write,
cx: &mut Context<'_>,
it: &clean::Item,
m: &clean::ProcMacro,
) {
let mut buffer = Buffer::new();
wrap_item(&mut buffer, |buffer| {
let name = it.name.expect("proc-macros always have names");
match m.kind {
MacroKind::Bang => {
write!(w, "{}!() {{ /* proc-macro */ }}", name);
write!(buffer, "{}!() {{ /* proc-macro */ }}", name);
}
MacroKind::Attr => {
write!(w, "#[{}]", name);
write!(buffer, "#[{}]", name);
}
MacroKind::Derive => {
write!(w, "#[derive({})]", name);
write!(buffer, "#[derive({})]", name);
if !m.helpers.is_empty() {
w.push_str("\n{\n");
w.push_str(" // Attributes available to this derive:\n");
buffer.push_str("\n{\n");
buffer.push_str(" // Attributes available to this derive:\n");
for attr in &m.helpers {
writeln!(w, " #[{}]", attr);
writeln!(buffer, " #[{}]", attr);
}
w.push_str("}\n");
buffer.push_str("}\n");
}
}
}
});
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
write!(w, "{}{}", buffer.into_inner(), document(cx, it, None, HeadingOffset::H2)).unwrap();
}

fn item_primitive(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
Expand Down

0 comments on commit fdd62cf

Please sign in to comment.