diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 15d378bdd7f..a07b8f4942b 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -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, diff --git a/tests/ui/needless_pass_by_value_proc_macro.rs b/tests/ui/needless_pass_by_value_proc_macro.rs index 3142210f9bf..78a0e92d179 100644 --- a/tests/ui/needless_pass_by_value_proc_macro.rs +++ b/tests/ui/needless_pass_by_value_proc_macro.rs @@ -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!() +}