From 93333f0d7b62df382913885ccf7e7c79702d090a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 22 Dec 2016 15:51:59 +0100 Subject: [PATCH 1/2] 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 ba705a84089c..3600abe0d7bf 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 000000000000..fab2fe626c3b --- /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() {} From ba59ba3afc85d238ae452a0c9fdf5e69ac4de258 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sun, 25 Dec 2016 17:49:39 +0100 Subject: [PATCH 2/2] fix rustfmt --- clippy_lints/src/lifetimes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 3600abe0d7bf..fa0afd90d332 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -287,7 +287,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.record(&None); } } - } + }, _ => (), } walk_ty(self, ty);