@@ -17,6 +17,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717use rustc_errors:: Applicability ;
1818use rustc_target:: spec:: abi:: Abi ;
1919use std:: borrow:: Cow ;
20+ use syntax:: ast:: Attribute ;
2021use syntax:: errors:: DiagnosticBuilder ;
2122use syntax_pos:: Span ;
2223
@@ -88,14 +89,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
8889
8990 match kind {
9091 FnKind :: ItemFn ( .., header, _, attrs) => {
91- if header. abi != Abi :: Rust {
92+ if header. abi != Abi :: Rust || requires_exact_signature ( attrs ) {
9293 return ;
9394 }
94- for a in attrs {
95- if a. meta_item_list ( ) . is_some ( ) && a. name ( ) == "proc_macro_derive" {
96- return ;
97- }
98- }
9995 } ,
10096 FnKind :: Method ( ..) => ( ) ,
10197 _ => return ,
@@ -323,6 +319,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
323319 }
324320}
325321
322+ /// Functions marked with these attributes must have the exact signature.
323+ fn requires_exact_signature ( attrs : & [ Attribute ] ) -> bool {
324+ attrs. iter ( ) . any ( |attr| {
325+ [ "proc_macro" , "proc_macro_attribute" , "proc_macro_derive" ]
326+ . iter ( )
327+ . any ( |& allow| attr. name ( ) == allow)
328+ } )
329+ }
330+
326331struct MovedVariablesCtxt < ' a , ' tcx : ' a > {
327332 cx : & ' a LateContext < ' a , ' tcx > ,
328333 moved_vars : FxHashSet < HirId > ,
0 commit comments