Skip to content

Commit 88750f9

Browse files
author
Michael Wright
committed
Fix extra_unused_lifetimes false positive
Fixes #4291
1 parent a3fcaee commit 88750f9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

clippy_lints/src/lifetimes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use syntax::source_map::Span;
99
use syntax::symbol::kw;
1010

1111
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};
1313

1414
declare_clippy_lint! {
1515
/// **What it does:** Checks for lifetime annotations which can be removed by
@@ -66,7 +66,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
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+
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+
}
7072
}
7173
}
7274

tests/ui/extra_unused_lifetimes.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,23 @@ impl X {
6161
fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
6262
}
6363

64+
// Methods implementing traits must have matching lifetimes
65+
mod issue4291 {
66+
#[derive(Debug)]
67+
pub struct Foo<'a>(&'a std::marker::PhantomData<u8>);
68+
69+
#[derive(Debug)]
70+
pub struct Bar<'a: 'b, 'b>(Foo<'a>, &'b std::marker::PhantomData<u8>);
71+
72+
trait LT {
73+
fn test<'a: 'b, 'b>(foo: &Foo<'a>, bar: &Bar<'a, 'b>);
74+
}
75+
76+
pub struct Baz;
77+
78+
impl LT for Baz {
79+
fn test<'a: 'b, 'b>(_foo: &Foo, _bar: &Bar) {}
80+
}
81+
}
82+
6483
fn main() {}

0 commit comments

Comments
 (0)