Closed Arnavion closed 7 years ago
I think we should generate the doc string, should be no problem with quote (I hope).
(The real solution here is that Rust should be hygienic wrt to lints and macros, but that's something of a long-term fix...)
///
is tricky but here is an example of generating doc comments with quote!
in svd2rust:
let comment = format!("0x{:02x} - {}",
register.address_offset,
respace(®ister.description));
quote! {
#[doc = #comment]
pub #field_name : #field_ty
}
@dtolnay why is ///
tricky?
@nrc because macro_rules macros like quote!
are not allowed to look inside them at compile time. They just receive a string containing the text of the comment, which is useless because at runtime we can no longer look in the string and interpolate the #variables it refers to.
fn main() {
println!("{}", stringify! {
/// Constructs a #struct_name
fn new() {}
});
}
# [ doc = r" Constructs a #struct_name" ] fn new ( ) { }
If I ever rewrite quote!
as a procedural macro then it can support interpolating doc comments.
It could add
#[allow(missing_docs)]
on the generated impl.Or it could unilaterally add a generic doc comment
/// Constructs a #struct_name
(not sure if quote supports this).