Closed
Description
The following code compiles:
#![feature(macro_rules)]
macro_rules! print_doccomment(
(
$doc:tt
fn $name:ident()
) => (
macro_rules! dummy( () => (
$doc
fn $name() {
println!("The doc for this function is `{}`", stringify!($doc));
}
))
dummy!()
)
)
print_doccomment!(
/// This is a doc comment
fn function_to_doc()
)
fn main() {
function_to_doc();
}
And prints "/// This is a doc comment". However, the token /// This is a doc comment
is not an item, which is the only thing that should parse for the first $doc
when dummy!
is expanded (according to @chris-morgan on IRC).
Note that I am using (a variation on) this in some code to transmit the doc comments on RPC-handling functions in response to the RPC "help". It would be great if there were a sanctioned way to parse or construct doccomments in macros.