mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Filter out proc_macro and proc_macro_attribute
This commit is contained in:
parent
1cdac4a9c7
commit
4896b259eb
2 changed files with 21 additions and 6 deletions
|
@ -17,6 +17,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
use rustc_errors::Applicability;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use std::borrow::Cow;
|
||||
use syntax::ast::Attribute;
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax_pos::Span;
|
||||
|
||||
|
@ -88,14 +89,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
match kind {
|
||||
FnKind::ItemFn(.., header, _, attrs) => {
|
||||
if header.abi != Abi::Rust {
|
||||
if header.abi != Abi::Rust || requires_exact_signature(attrs) {
|
||||
return;
|
||||
}
|
||||
for a in attrs {
|
||||
if a.meta_item_list().is_some() && a.name() == "proc_macro_derive" {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
FnKind::Method(..) => (),
|
||||
_ => return,
|
||||
|
@ -323,6 +319,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
}
|
||||
}
|
||||
|
||||
/// Functions marked with these attributes must have the exact signature.
|
||||
fn requires_exact_signature(attrs: &[Attribute]) -> bool {
|
||||
attrs.iter().any(|attr| {
|
||||
["proc_macro", "proc_macro_attribute", "proc_macro_derive"]
|
||||
.iter()
|
||||
.any(|&allow| attr.name() == allow)
|
||||
})
|
||||
}
|
||||
|
||||
struct MovedVariablesCtxt<'a, 'tcx: 'a> {
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
moved_vars: FxHashSet<HirId>,
|
||||
|
|
|
@ -9,3 +9,13 @@ use proc_macro::TokenStream;
|
|||
pub fn foo(_input: TokenStream) -> TokenStream {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn bar(_input: TokenStream) -> TokenStream {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn baz(_args: TokenStream, _input: TokenStream) -> TokenStream {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue