How to embed a Rust macro variable into documentation?
问题 I'd like to use a macro variable in the macro-generated documentation: macro_rules! impl_foo { ($name:ident) => { /// Returns a new `$name`. fn myfoo() -> $name { } }; } However, the variable won't be substituted. I also tried using the #[doc] attribute: macro_rules! impl_foo { ($name:ident) => { #[doc = concat!("Returns a new `", $name, "`.")] fn myfoo() -> $name { } }; } This one even fails to parse: unexpected token: 'concat' 回答1: This can be done using a recursive macro: macro_rules! impl