Skip to content

Commit

Permalink
Fix lifetime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Aug 18, 2024
1 parent 8a42b9f commit cc1bbde
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/ui/crashes/needless_lifetimes_impl_trait.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '_ {
Expand Down
20 changes: 16 additions & 4 deletions tests/ui/crashes/needless_lifetimes_impl_trait.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

8 changes: 8 additions & 0 deletions tests/ui/extra_unused_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/extra_unused_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/needless_lifetimes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 13 additions & 1 deletion tests/ui/needless_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,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
|
Expand Down Expand Up @@ -553,5 +565,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 {
LL + fn one_input(x: &u8) -> &u8 {
|

error: aborting due to 46 previous errors
error: aborting due to 47 previous errors

0 comments on commit cc1bbde

Please sign in to comment.