@@ -9,7 +9,7 @@ use syntax::source_map::Span;
99use syntax:: symbol:: kw;
1010
1111use crate :: reexport:: * ;
12- use crate :: utils:: { last_path_segment, span_lint} ;
12+ use crate :: utils:: { last_path_segment, span_lint, trait_ref_of_method } ;
1313
1414declare_clippy_lint ! {
1515 /// **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]);
6060impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for Lifetimes {
6161 fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item ) {
6262 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 ) ;
6464 }
6565 }
6666
6767 fn check_impl_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx ImplItem ) {
6868 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+ ) ;
7078 }
7179 }
7280
@@ -76,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
7684 TraitMethod :: Required ( _) => None ,
7785 TraitMethod :: Provided ( id) => Some ( id) ,
7886 } ;
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 ) ;
8088 }
8189 }
8290}
@@ -95,6 +103,7 @@ fn check_fn_inner<'a, 'tcx>(
95103 body : Option < BodyId > ,
96104 generics : & ' tcx Generics ,
97105 span : Span ,
106+ report_extra_lifetimes : bool ,
98107) {
99108 if in_external_macro ( cx. sess ( ) , span) || has_where_lifetimes ( cx, & generics. where_clause ) {
100109 return ;
@@ -144,7 +153,9 @@ fn check_fn_inner<'a, 'tcx>(
144153 (or replaced with `'_` if needed by type declaration)",
145154 ) ;
146155 }
147- report_extra_lifetimes ( cx, decl, generics) ;
156+ if report_extra_lifetimes {
157+ self :: report_extra_lifetimes ( cx, decl, generics) ;
158+ }
148159}
149160
150161fn could_use_elision < ' a , ' tcx > (
0 commit comments