I am getting warning: unused attribute
while trying to use function argument attributes.
The attribute is parsed with syn::parse::<syn::ItemFn>(input)
:
#[proc_macro_attribute]
pub fn test_attr(_args: TokenStream, input: TokenStream) -> TokenStream {
let function_result = syn::parse::<syn::ItemFn>(input)
.map_err(|error| error.span().unstable().error(error.to_string()))
.map_err(|d| d.help(String::from("#[test_attr] can only be used on functions")));
// ...
}
The function declaration itself is not very interesting:
#[test_attr]
pub fn test(#[foo] _bar: ()) {
// why is `#[foo]` considered to be unused?
// look at codegen/src/lib.rs for the `#[test_attr]` codegen implementation
// which actually uses `#[foo]`
}
The full warning is:
warning: unused attribute
--> lib\src\lib.rs:6:13
|
6 | pub fn test(#[foo] _bar: ()) {
| ^^^^^^
|
= note: `#[warn(unused_attributes)]` on by default
I have created an example repo so you can test it yourself:
The compiler I am currently using is:
$ rustc --version --verbose
rustc 1.38.0-nightly (60960a260 2019-08-12)
binary: rustc
commit-hash: 60960a260f7b5c695fd0717311d72ce62dd4eb43
commit-date: 2019-08-12
host: x86_64-pc-windows-gnu
release: 1.38.0-nightly
LLVM version: 9.0
What am I doing wrong?