“Unused attribute” warning for custom derive attribute


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?


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


I register my custom attribute with


I have tried both

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


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

but warning is still emitted.


@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.


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


You are right — they have gone! Thank you!


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


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


@kriomant should be fixed on the most recent nighties.


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