Fix extra_unused_lifetimes false positive

Fixes #4291
This commit is contained in:
Michael Wright 2019-08-31 08:16:04 +02:00
parent a3fcaee562
commit 88750f9ad7
2 changed files with 23 additions and 2 deletions

View file

@ -9,7 +9,7 @@ use syntax::source_map::Span;
use syntax::symbol::kw;
use crate::reexport::*;
use crate::utils::{last_path_segment, span_lint};
use crate::utils::{last_path_segment, span_lint, trait_ref_of_method};
declare_clippy_lint! {
/// **What it does:** Checks for lifetime annotations which can be removed by
@ -66,7 +66,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if let ImplItemKind::Method(ref sig, id) = item.node {
check_fn_inner(cx, &sig.decl, Some(id), &item.generics, item.span);
if trait_ref_of_method(cx, item.hir_id).is_none() {
check_fn_inner(cx, &sig.decl, Some(id), &item.generics, item.span);
}
}
}

View file

@ -61,4 +61,23 @@ impl X {
fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
}
// Methods implementing traits must have matching lifetimes
mod issue4291 {
#[derive(Debug)]
pub struct Foo<'a>(&'a std::marker::PhantomData<u8>);
#[derive(Debug)]
pub struct Bar<'a: 'b, 'b>(Foo<'a>, &'b std::marker::PhantomData<u8>);
trait LT {
fn test<'a: 'b, 'b>(foo: &Foo<'a>, bar: &Bar<'a, 'b>);
}
pub struct Baz;
impl LT for Baz {
fn test<'a: 'b, 'b>(_foo: &Foo, _bar: &Bar) {}
}
}
fn main() {}