@@ -60,15 +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- if trait_ref_of_method ( cx, item. hir_id ) . is_none ( ) {
70- check_fn_inner ( cx, & sig. decl , Some ( id) , & item. generics , item. span ) ;
71- }
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+ ) ;
7278 }
7379 }
7480
@@ -78,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
7884 TraitMethod :: Required ( _) => None ,
7985 TraitMethod :: Provided ( id) => Some ( id) ,
8086 } ;
81- check_fn_inner ( cx, & sig. decl , body, & item. generics , item. span ) ;
87+ check_fn_inner ( cx, & sig. decl , body, & item. generics , item. span , true ) ;
8288 }
8389 }
8490}
@@ -97,6 +103,7 @@ fn check_fn_inner<'a, 'tcx>(
97103 body : Option < BodyId > ,
98104 generics : & ' tcx Generics ,
99105 span : Span ,
106+ report_extra_lifetimes : bool ,
100107) {
101108 if in_external_macro ( cx. sess ( ) , span) || has_where_lifetimes ( cx, & generics. where_clause ) {
102109 return ;
@@ -146,7 +153,9 @@ fn check_fn_inner<'a, 'tcx>(
146153 (or replaced with `'_` if needed by type declaration)",
147154 ) ;
148155 }
149- report_extra_lifetimes ( cx, decl, generics) ;
156+ if report_extra_lifetimes {
157+ self :: report_extra_lifetimes ( cx, decl, generics) ;
158+ }
150159}
151160
152161fn could_use_elision < ' a , ' tcx > (
0 commit comments