Fix lifetime tests

This commit is contained in:
Samuel Moelius 2024-08-18 07:31:03 -04:00
parent 0a11c5c49a
commit f2495a1777
6 changed files with 46 additions and 8 deletions

View File

@ -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 + '_ {

View File

@ -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

View File

@ -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<T> {
fn hey() {}
}
struct OtherBox<T: ?Sized>(Box<T>);
impl<T: Source + ?Sized> Source for OtherBox<T> {
fn hey() {}
}
}
// Should not lint

View File

@ -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

View File

@ -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 }

View File

@ -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