Turn duplicated_attributes into a late lint
This commit is contained in:
parent
2202493a67
commit
f7d49a340d
8 changed files with 77 additions and 39 deletions
|
|
@ -176,3 +176,17 @@ pub fn with_empty_docs(_attr: TokenStream, input: TokenStream) -> TokenStream {
|
|||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn duplicated_attr(_attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let item = parse_macro_input!(input as syn::Item);
|
||||
let attrs: Vec<syn::Attribute> = vec![];
|
||||
quote! {
|
||||
#(#attrs)*
|
||||
#[allow(unused)]
|
||||
#[allow(unused)]
|
||||
#[allow(unused)]
|
||||
#item
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
//@aux-build:proc_macro_attr.rs
|
||||
|
||||
#![warn(clippy::duplicated_attributes)]
|
||||
#![cfg(any(unix, windows))]
|
||||
#![allow(dead_code)]
|
||||
#![allow(dead_code)] //~ ERROR: duplicated attribute
|
||||
#![cfg(any(unix, windows))] // Should not warn!
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macro_attr;
|
||||
|
||||
#[cfg(any(unix, windows, target_os = "linux"))]
|
||||
#[allow(dead_code)]
|
||||
#[allow(dead_code)] //~ ERROR: duplicated attribute
|
||||
|
|
@ -12,7 +17,10 @@ fn foo() {}
|
|||
|
||||
#[cfg(unix)]
|
||||
#[cfg(windows)]
|
||||
#[cfg(unix)] //~ ERROR: duplicated attribute
|
||||
#[cfg(unix)] // cfgs are not handled
|
||||
fn bar() {}
|
||||
|
||||
#[proc_macro_attr::duplicated_attr()] // Should not warn!
|
||||
fn babar() {}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
error: duplicated attribute
|
||||
--> tests/ui/duplicated_attributes.rs:4:10
|
||||
--> tests/ui/duplicated_attributes.rs:6:10
|
||||
|
|
||||
LL | #![allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: first defined here
|
||||
--> tests/ui/duplicated_attributes.rs:3:10
|
||||
--> tests/ui/duplicated_attributes.rs:5:10
|
||||
|
|
||||
LL | #![allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
help: remove this attribute
|
||||
--> tests/ui/duplicated_attributes.rs:4:10
|
||||
--> tests/ui/duplicated_attributes.rs:6:10
|
||||
|
|
||||
LL | #![allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -18,38 +18,21 @@ LL | #![allow(dead_code)]
|
|||
= help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`
|
||||
|
||||
error: duplicated attribute
|
||||
--> tests/ui/duplicated_attributes.rs:9:9
|
||||
--> tests/ui/duplicated_attributes.rs:14:9
|
||||
|
|
||||
LL | #[allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: first defined here
|
||||
--> tests/ui/duplicated_attributes.rs:8:9
|
||||
--> tests/ui/duplicated_attributes.rs:13:9
|
||||
|
|
||||
LL | #[allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
help: remove this attribute
|
||||
--> tests/ui/duplicated_attributes.rs:9:9
|
||||
--> tests/ui/duplicated_attributes.rs:14:9
|
||||
|
|
||||
LL | #[allow(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: duplicated attribute
|
||||
--> tests/ui/duplicated_attributes.rs:15:7
|
||||
|
|
||||
LL | #[cfg(unix)]
|
||||
| ^^^^
|
||||
|
|
||||
note: first defined here
|
||||
--> tests/ui/duplicated_attributes.rs:13:7
|
||||
|
|
||||
LL | #[cfg(unix)]
|
||||
| ^^^^
|
||||
help: remove this attribute
|
||||
--> tests/ui/duplicated_attributes.rs:15:7
|
||||
|
|
||||
LL | #[cfg(unix)]
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -57,5 +57,41 @@ error: no need to put clippy lints behind a `clippy` cfg
|
|||
LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg, clippy::maybe_misused_cfg)]`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: duplicated attribute
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:8:26
|
||||
|
|
||||
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: first defined here
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:6:26
|
||||
|
|
||||
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
|
||||
| ^^^^^^^^^
|
||||
help: remove this attribute
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:8:26
|
||||
|
|
||||
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
|
||||
| ^^^^^^^^^
|
||||
= note: `-D clippy::duplicated-attributes` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`
|
||||
|
||||
error: duplicated attribute
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:17:25
|
||||
|
|
||||
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: first defined here
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:15:25
|
||||
|
|
||||
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
|
||||
| ^^^^^^^^^
|
||||
help: remove this attribute
|
||||
--> tests/ui/unnecessary_clippy_cfg.rs:17:25
|
||||
|
|
||||
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg, clippy::maybe_misused_cfg))]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//@aux-build:proc_macro_derive.rs
|
||||
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::duplicated_attributes)]
|
||||
#![warn(clippy::useless_attribute)]
|
||||
#![warn(unreachable_pub)]
|
||||
#![feature(rustc_private)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//@aux-build:proc_macro_derive.rs
|
||||
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::duplicated_attributes)]
|
||||
#![warn(clippy::useless_attribute)]
|
||||
#![warn(unreachable_pub)]
|
||||
#![feature(rustc_private)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue