Auto merge of #3868 - taiki-e:needless_pass_by_value, r=phansch

Filter out proc_macro and proc_macro_attribute

Related to https://github.com/rust-lang/rust-clippy/pull/1617

Fixes https://github.com/rust-lang/rust-clippy/issues/3067 (this issue has already been closed, but in fact the false positive in `#[proc_macro]` and `#[proc_macro_attribute]` has not been fixed yet)
This commit is contained in:
bors 2019-03-12 06:01:00 +00:00
commit 94a8d9cbcd
2 changed files with 21 additions and 6 deletions

View File

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

View File

@ -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!()
}