diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index ba705a84089..fa0afd90d33 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -281,6 +281,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { TyPath(ref path) => { self.collect_anonymous_lifetimes(path, ty); }, + TyImplTrait(ref param_bounds) => { + for bound in param_bounds { + if let RegionTyParamBound(_) = *bound { + self.record(&None); + } + } + }, _ => (), } walk_ty(self, ty); diff --git a/tests/run-pass/needless_lifetimes_impl_trait.rs b/tests/run-pass/needless_lifetimes_impl_trait.rs new file mode 100644 index 00000000000..fab2fe626c3 --- /dev/null +++ b/tests/run-pass/needless_lifetimes_impl_trait.rs @@ -0,0 +1,22 @@ +#![feature(plugin)] +#![plugin(clippy)] +#![feature(conservative_impl_trait)] +#![deny(needless_lifetime)] + +trait Foo {} + +struct Bar {} + +struct Baz<'a> { + bar: &'a Bar, +} + +impl<'a> Foo for Baz<'a> {} + +impl Bar { + fn baz<'a>(&'a self) -> impl Foo + 'a { + Baz { bar: self } + } +} + +fn main() {}