From f2495a17772e0f90fa00fc8838c12b30b4a1c46e Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Sun, 18 Aug 2024 07:31:03 -0400 Subject: [PATCH] Fix lifetime tests --- .../needless_lifetimes_impl_trait.fixed | 2 +- .../needless_lifetimes_impl_trait.stderr | 20 +++++++++++++++---- tests/ui/extra_unused_lifetimes.rs | 8 ++++++++ tests/ui/extra_unused_lifetimes.stderr | 8 +++++++- tests/ui/needless_lifetimes.fixed | 2 +- tests/ui/needless_lifetimes.stderr | 14 ++++++++++++- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index 8bd9eea75bb..837069cae6d 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -9,7 +9,7 @@ struct Baz<'a> { bar: &'a Bar, } -impl<'a> Foo for Baz<'a> {} +impl Foo for Baz<'_> {} impl Bar { fn baz(&self) -> impl Foo + '_ { diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr index 3a2d1f4410e..bed6aab25c4 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr @@ -1,8 +1,8 @@ error: the following explicit lifetimes could be elided: 'a - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12 + --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:12:6 | -LL | fn baz<'a>(&'a self) -> impl Foo + 'a { - | ^^ ^^ ^^ +LL | impl<'a> Foo for Baz<'a> {} + | ^^ ^^ | note: the lint level is defined here --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:1:9 @@ -11,9 +11,21 @@ LL | #![deny(clippy::needless_lifetimes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: elide the lifetimes | +LL - impl<'a> Foo for Baz<'a> {} +LL + impl Foo for Baz<'_> {} + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12 + | +LL | fn baz<'a>(&'a self) -> impl Foo + 'a { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | LL - fn baz<'a>(&'a self) -> impl Foo + 'a { LL + fn baz(&self) -> impl Foo + '_ { | -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index cdfaf8d3afe..17d2ed9f50c 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -114,9 +114,17 @@ pub trait Source { fn hey(); } + // Should lint. The response to the above comment incorrectly called this a false positive. The + // lifetime `'a` can be removed, as demonstrated below. impl<'a, T: Source + ?Sized + 'a> Source for Box { fn hey() {} } + + struct OtherBox(Box); + + impl Source for OtherBox { + fn hey() {} + } } // Should not lint diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index 56292cb5d1a..85fbb7568ff 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -37,5 +37,11 @@ error: this lifetime isn't used in the function definition LL | pub fn something<'c>() -> Self { | ^^ -error: aborting due to 6 previous errors +error: this lifetime isn't used in the impl + --> tests/ui/extra_unused_lifetimes.rs:119:10 + | +LL | impl<'a, T: Source + ?Sized + 'a> Source for Box { + | ^^ + +error: aborting due to 7 previous errors diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index d1787b35abd..e4bb7f86d12 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -329,7 +329,7 @@ mod issue2944 { bar: &'a Bar, } - impl<'a> Foo for Baz<'a> {} + impl Foo for Baz<'_> {} impl Bar { fn baz(&self) -> impl Foo + '_ { Baz { bar: self } diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 50f845e2d92..166e6d0eabf 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -335,6 +335,18 @@ LL - fn needless_lt<'a>(_x: &'a u8) {} LL + fn needless_lt(_x: &u8) {} | +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/needless_lifetimes.rs:332:10 + | +LL | impl<'a> Foo for Baz<'a> {} + | ^^ ^^ + | +help: elide the lifetimes + | +LL - impl<'a> Foo for Baz<'a> {} +LL + impl Foo for Baz<'_> {} + | + error: the following explicit lifetimes could be elided: 'a --> tests/ui/needless_lifetimes.rs:334:16 | @@ -564,5 +576,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 { LL + fn one_input(x: &u8) -> &u8 { | -error: aborting due to 47 previous errors +error: aborting due to 48 previous errors