First, write a derive macro which generates a declarative macro:
use quote::quote;
#[proc_macro_derive(MyDeriveMacro)]
pub fn derive_my_derive_macro(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
proc_macro::TokenStream::from(quote! {
#[macro_export]
macro_rules! my_generated_macro {
($my_macro_parameter: expr) => {};
}
})
}
Then in another crate, import this derive macro and use it:
#[derive(MyDeriveMacro)]
struct MyStruct {}
Then use
to generate the docs.
The doc for my_generated_macro should be
macro_rules! my_generated_macro {
($my_macro_parameter: expr) => {};
}
But instead, it turns out
macro_rules! my_generated_macro {
MyDeriveMacro => {};
}
This is very confusing, since the parameters of the generated declarative macro are all missing, and instead is name of the derive macro which generated it.
Meta
rustc --version --verbose:
rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-apple-darwin
release: 1.48.0
LLVM version: 11.0
First, write a derive macro which generates a declarative macro:
Then in another crate, import this derive macro and use it:
Then use
to generate the docs.
The doc for
my_generated_macroshould beBut instead, it turns out
This is very confusing, since the parameters of the generated declarative macro are all missing, and instead is name of the derive macro which generated it.
Meta
rustc --version --verbose: