Hello,
it's just me and my annoying experiments with Macros
I noticed something, when I use a macro with its full path, syn can't detect it.
here's a concrete example :
Macros code : ( in lib "ex: crateMyMacros")
// this is a dummy macro
#[proc_macro_attribute]
pub fn dummy_macro(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let input = parse_macro_input!(item as syn::Item);
println!("Hello :D");
let code = quote!(
#input
);
TokenStream::from(code)
}
// this macro list all function attributes
#[proc_macro_attribute]
pub fn scan(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
println!("scan started !");
let input = parse_macro_input!(item as syn::ItemFn);
input.attrs.iter().for_each(|attr| {
if let Some(ident) = attr.path().get_ident() {
println!("ident = {}", ident);
}
});
let code = quote!(
#input
);
TokenStream::from(code)
}
Bin code (crateApp) :
#[scan]
#[dummy_macro]
fn test() {
println!("TEST");
}
result :
scan started !
ident = dummy_macro
Hello :D
#[scan]
#[crateMyMacros::dummy_macro]
fn test_with_strange_behavior() {
println!("TEST");
}
result :
scan started !
Hello :D
as you can see, when the macro name contains the full path #[crateMyMacros::dummy_macro], it is not detected !!
is this a syn bug? or is it one of the limitations of the Rust language ?
Thanks in advance for your feedback.