@@ -17,6 +17,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
17
17
use rustc_errors:: Applicability ;
18
18
use rustc_target:: spec:: abi:: Abi ;
19
19
use std:: borrow:: Cow ;
20
+ use syntax:: ast:: Attribute ;
20
21
use syntax:: errors:: DiagnosticBuilder ;
21
22
use syntax_pos:: Span ;
22
23
@@ -88,14 +89,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
88
89
89
90
match kind {
90
91
FnKind :: ItemFn ( .., header, _, attrs) => {
91
- if header. abi != Abi :: Rust {
92
+ if header. abi != Abi :: Rust || requires_exact_signature ( attrs ) {
92
93
return ;
93
94
}
94
- for a in attrs {
95
- if a. meta_item_list ( ) . is_some ( ) && a. name ( ) == "proc_macro_derive" {
96
- return ;
97
- }
98
- }
99
95
} ,
100
96
FnKind :: Method ( ..) => ( ) ,
101
97
_ => return ,
@@ -323,6 +319,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
323
319
}
324
320
}
325
321
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
+
326
331
struct MovedVariablesCtxt < ' a , ' tcx : ' a > {
327
332
cx : & ' a LateContext < ' a , ' tcx > ,
328
333
moved_vars : FxHashSet < HirId > ,
0 commit comments