@@ -9,7 +9,7 @@ use syntax::source_map::Span;
9
9
use syntax:: symbol:: kw;
10
10
11
11
use crate :: reexport:: * ;
12
- use crate :: utils:: { last_path_segment, span_lint} ;
12
+ use crate :: utils:: { last_path_segment, span_lint, trait_ref_of_method } ;
13
13
14
14
declare_clippy_lint ! {
15
15
/// **What it does:** Checks for lifetime annotations which can be removed by
@@ -60,13 +60,21 @@ declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]);
60
60
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for Lifetimes {
61
61
fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item ) {
62
62
if let ItemKind :: Fn ( ref decl, _, ref generics, id) = item. node {
63
- check_fn_inner ( cx, decl, Some ( id) , generics, item. span ) ;
63
+ check_fn_inner ( cx, decl, Some ( id) , generics, item. span , true ) ;
64
64
}
65
65
}
66
66
67
67
fn check_impl_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx ImplItem ) {
68
68
if let ImplItemKind :: Method ( ref sig, id) = item. node {
69
- check_fn_inner ( cx, & sig. decl , Some ( id) , & item. generics , item. span ) ;
69
+ let report_extra_lifetimes = trait_ref_of_method ( cx, item. hir_id ) . is_none ( ) ;
70
+ check_fn_inner (
71
+ cx,
72
+ & sig. decl ,
73
+ Some ( id) ,
74
+ & item. generics ,
75
+ item. span ,
76
+ report_extra_lifetimes,
77
+ ) ;
70
78
}
71
79
}
72
80
@@ -76,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
76
84
TraitMethod :: Required ( _) => None ,
77
85
TraitMethod :: Provided ( id) => Some ( id) ,
78
86
} ;
79
- check_fn_inner ( cx, & sig. decl , body, & item. generics , item. span ) ;
87
+ check_fn_inner ( cx, & sig. decl , body, & item. generics , item. span , true ) ;
80
88
}
81
89
}
82
90
}
@@ -95,6 +103,7 @@ fn check_fn_inner<'a, 'tcx>(
95
103
body : Option < BodyId > ,
96
104
generics : & ' tcx Generics ,
97
105
span : Span ,
106
+ report_extra_lifetimes : bool ,
98
107
) {
99
108
if in_external_macro ( cx. sess ( ) , span) || has_where_lifetimes ( cx, & generics. where_clause ) {
100
109
return ;
@@ -144,7 +153,9 @@ fn check_fn_inner<'a, 'tcx>(
144
153
(or replaced with `'_` if needed by type declaration)",
145
154
) ;
146
155
}
147
- report_extra_lifetimes ( cx, decl, generics) ;
156
+ if report_extra_lifetimes {
157
+ self :: report_extra_lifetimes ( cx, decl, generics) ;
158
+ }
148
159
}
149
160
150
161
fn could_use_elision < ' a , ' tcx > (
0 commit comments