Fix unused attributes on macro_rules.

This commit is contained in:
Eric Huss 2021-05-15 16:10:17 -07:00
parent 17f30e5451
commit 5bbc240ffb
4 changed files with 70 additions and 3 deletions

View file

@ -0,0 +1,34 @@
#![deny(unused_attributes)]
// Unused attributes on macro_rules requires special handling since the
// macro_rules definition does not survive towards HIR.
// A sample of various built-in attributes.
#[macro_export]
#[macro_use] //~ ERROR unused attribute
#[path="foo"] //~ ERROR unused attribute
#[recursion_limit="1"] //~ ERROR unused attribute
//~| ERROR crate-level attribute should be an inner attribute
macro_rules! foo {
() => {};
}
// The following should not warn about unused attributes.
#[allow(unused)]
macro_rules! foo2 {
() => {};
}
#[cfg(FALSE)]
macro_rules! foo {
() => {};
}
/// Some docs
#[deprecated]
#[doc = "more docs"]
#[macro_export]
macro_rules! bar {
() => {};
}
fn main() {}

View file

@ -0,0 +1,32 @@
error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:7:1
|
LL | #[macro_use]
| ^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-attr-macro-rules.rs:1:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:8:1
|
LL | #[path="foo"]
| ^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:9:1
|
LL | #[recursion_limit="1"]
| ^^^^^^^^^^^^^^^^^^^^^^
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/unused-attr-macro-rules.rs:9:1
|
LL | #[recursion_limit="1"]
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors