Description
As people may or may not be aware, in embedded we generate Rust code from MCU register descriptions, including remarks and metadata provided by those descriptions as comments with a tool called svd2rust
and republish those as crates for common use. Those look like e.g. https://docs.rs/stm32f0/0.9.0/stm32f0/stm32f0x0/adc/ccr/struct.TSEN_W.html
Now as you can imagine the generated code files are huge which comes with the usual negative side effects that everything about using them is happening in slow motion; compilation is slow and we regularly de-rail or least block docs.rs infrastructure for considerable amounts of time.
Reducing and improving our generated code has been a huge focus for us but the #[doc]
comments were not too much of a concern except for saving a few bytes, however recently rust-lang/rust#65750 has landed which I presume would be a massive benefit for use if we could change our large number of single line comments to ///
instead.
Now the question is: How can we get there?
We're using quote!
extensively so our code looks like:
let doc = format!("Checks if the value of the field is `{}`", pc);
enum_items.push(quote! {
#[doc = #doc]
#[inline(always)]
pub fn #is_variant(&self) -> bool {
*self == #pc_r::#pc
}
});
Changing to
let doc = format!("Checks if the value of the field is `{}`", pc);
enum_items.push(quote! {
/// #doc
#[inline(always)]
pub fn #is_variant(&self) -> bool {
*self == #pc_r::#pc
}
});
does not work because the #doc
is not interpolated anymore
Changing to
let doc = Literal::string(&format!("Checks if the value of the field is `{}`", pc));
enum_items.push(quote! {
#doc
#[inline(always)]
pub fn #is_variant(&self) -> bool {
*self == #pc_r::#pc
}
});
does not work because quote!
will quote the comment.
Parsing it does also not work because it will convert it back to a #[doc]
attribute.
Is there any way to do this now or is there any plan to tackle this?