Open hlf20010508 opened 1 month ago
I also found that it doesn't work for
pub async fn test() {
async {
println!("test");
}
.await;
}
The produced function can be detected as not from a macro expansion by preserving the token spans, e.g.
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_macro_input, ItemFn};
#[proc_macro_attribute]
pub fn add_trace(_args: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemFn);
let mut tokens = input.sig.to_token_stream();
input.block.brace_token.surround(&mut tokens, |tokens| {
let fn_name = input.sig.ident.to_string();
let fn_block = &input.block;
tokens.extend(quote! {
let func_path = module_path!().to_string() + "::" + #fn_name;
tracing::trace!("->|{}", func_path);
let result = #fn_block;
tracing::trace!("<-|{}", func_path);
result
});
});
tokens.into()
}
Summary
I wrote a
proc_macro_attribute
, only added some trace to the code block, and theunused_async
doesn't work anymore.I tried to work around it in dylint, copied the code of
unused_async
.If I remove condition
!span.from_expansion()
and usecall_site
for macro span, it worked.Is there anything more should be considered for macros that I don't know?
Lint Name
unused_async
Reproducer
Attribute:
Fn:
Version