“Unused attribute” warning for custom derive attribute


#1

My library mockers uses compiler plugin to provide custom #[derive(Mock)] attribute. After some of latest nightly rustc releasesa all uses of this attribute causes “unused attribute” to be emitted.
Is this bug?


#2

You need to register an attribute into the registry. http://manishearth.github.io/rust-internals-docs/rustc_plugin/registry/struct.Registry.html#method.register_attribute


#3

I register my custom attribute with

reg.register_syntax_extension(intern("derive_Mock"),
                              SyntaxExtension::MultiDecorator(Box::new(derive_mock)));

I have tried both

reg.register_attribute("derive_Mock".to_owned(), AttributeType::Whitelisted);

and

reg.register_attribute("Mock".to_owned(), AttributeType::Whitelisted);

but warning is still emitted.


#4

@kriomant Thanks for the report!

The unused attribute warnings are actually from the #[cfg(test)] attributes on the items that derive_Mock creates. These decorator-generated items stopped being cfg-processed in https://github.com/rust-lang/rust/pull/33706.

I fixed this in https://github.com/rust-lang/rust/pull/34295 – the warnings should go away once it lands.


#5

@kriomant
There should be no unused attributes warnings on the most recent nighties.


#6

You are right — they have gone! Thank you!


#7

@jseyfried, warnings are emitted again with 1.10.0-nightly (476fe6eef 2016-05-21).


#8

@kriomant sorry – fixed in #34654 (should land soon) and added a regression test this time.


#9

@kriomant should be fixed on the most recent nighties.


#10

Yes, latest nightly is fine. Thank you again :slight_smile: