@@ -3,10 +3,9 @@ use rustc::ty::subst::Subst;
3
3
use rustc:: ty:: TypeVariants ;
4
4
use rustc:: ty;
5
5
use rustc:: hir:: * ;
6
- use syntax:: ast:: { Attribute , MetaItemKind } ;
7
6
use syntax:: codemap:: Span ;
8
7
use utils:: paths;
9
- use utils:: { match_path, span_lint_and_then} ;
8
+ use utils:: { is_automatically_derived , match_path, span_lint_and_then} ;
10
9
11
10
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
12
11
/// explicitly.
@@ -75,7 +74,7 @@ impl LateLintPass for Derive {
75
74
fn check_item ( & mut self , cx : & LateContext , item : & Item ) {
76
75
if let ItemImpl ( _, _, _, Some ( ref trait_ref) , _, _) = item. node {
77
76
let ty = cx. tcx . lookup_item_type ( cx. tcx . map . local_def_id ( item. id ) ) . ty ;
78
- let is_automatically_derived = item. attrs . iter ( ) . any ( is_automatically_derived ) ;
77
+ let is_automatically_derived = is_automatically_derived ( & * item. attrs ) ;
79
78
80
79
check_hash_peq ( cx, item. span , trait_ref, ty, is_automatically_derived) ;
81
80
@@ -97,7 +96,7 @@ fn check_hash_peq<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, span: Span, trait_re
97
96
98
97
// Look for the PartialEq implementations for `ty`
99
98
peq_trait_def. for_each_relevant_impl( cx. tcx, ty, |impl_id| {
100
- let peq_is_automatically_derived = cx. tcx. get_attrs( impl_id) . iter ( ) . any ( is_automatically_derived ) ;
99
+ let peq_is_automatically_derived = is_automatically_derived ( & cx. tcx. get_attrs( impl_id) ) ;
101
100
102
101
if peq_is_automatically_derived == hash_is_automatically_derived {
103
102
return ;
@@ -174,12 +173,3 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
174
173
} ) ;
175
174
}
176
175
}
177
-
178
- /// Checks for the `#[automatically_derived]` attribute all `#[derive]`d implementations have.
179
- fn is_automatically_derived ( attr : & Attribute ) -> bool {
180
- if let MetaItemKind :: Word ( ref word) = attr. node . value . node {
181
- word == & "automatically_derived"
182
- } else {
183
- false
184
- }
185
- }
0 commit comments