From 93333f0d7b62df382913885ccf7e7c79702d090a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 22 Dec 2016 15:51:59 +0100 Subject: [PATCH] support impl trait for needless lifetimes --- clippy_lints/src/lifetimes.rs | 7 ++++++ .../run-pass/needless_lifetimes_impl_trait.rs | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/run-pass/needless_lifetimes_impl_trait.rs diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index ba705a84089..3600abe0d7b 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() {}