diff options
| author | Samuel Moelius <sam@moeli.us> | 2024-08-18 07:31:03 -0400 |
|---|---|---|
| committer | Samuel Moelius <sam@moeli.us> | 2024-09-25 13:48:15 -0400 |
| commit | f2495a17772e0f90fa00fc8838c12b30b4a1c46e (patch) | |
| tree | 1ced6e51b2b99f160afc956ff6415324d14733cf | |
| parent | 0a11c5c49ac7412492fc3bc73100912ea11c6360 (diff) | |
| download | rust-f2495a17772e0f90fa00fc8838c12b30b4a1c46e.tar.gz rust-f2495a17772e0f90fa00fc8838c12b30b4a1c46e.zip | |
Fix lifetime tests
| -rw-r--r-- | tests/ui/crashes/needless_lifetimes_impl_trait.fixed | 2 | ||||
| -rw-r--r-- | tests/ui/crashes/needless_lifetimes_impl_trait.stderr | 20 | ||||
| -rw-r--r-- | tests/ui/extra_unused_lifetimes.rs | 8 | ||||
| -rw-r--r-- | tests/ui/extra_unused_lifetimes.stderr | 8 | ||||
| -rw-r--r-- | tests/ui/needless_lifetimes.fixed | 2 | ||||
| -rw-r--r-- | 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 @@ mod second_case { 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<T> { fn hey() {} } + + struct OtherBox<T: ?Sized>(Box<T>); + + impl<T: Source + ?Sized> Source for OtherBox<T> { + 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<T> { + | ^^ + +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 @@ -336,6 +336,18 @@ 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 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { @@ -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 |
