Skip to content

Commit 6c62bb0

Browse files
committed
Fix lifetime tests
1 parent e28d44f commit 6c62bb0

6 files changed

+46
-8
lines changed

tests/ui/crashes/needless_lifetimes_impl_trait.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct Baz<'a> {
99
bar: &'a Bar,
1010
}
1111

12-
impl<'a> Foo for Baz<'a> {}
12+
impl Foo for Baz<'_> {}
1313

1414
impl Bar {
1515
fn baz(&self) -> impl Foo + '_ {
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: the following explicit lifetimes could be elided: 'a
2-
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12
2+
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:12:6
33
|
4-
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
5-
| ^^ ^^ ^^
4+
LL | impl<'a> Foo for Baz<'a> {}
5+
| ^^ ^^
66
|
77
note: the lint level is defined here
88
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:1:9
@@ -11,9 +11,21 @@ LL | #![deny(clippy::needless_lifetimes)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: elide the lifetimes
1313
|
14+
LL - impl<'a> Foo for Baz<'a> {}
15+
LL + impl Foo for Baz<'_> {}
16+
|
17+
18+
error: the following explicit lifetimes could be elided: 'a
19+
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12
20+
|
21+
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
22+
| ^^ ^^ ^^
23+
|
24+
help: elide the lifetimes
25+
|
1426
LL - fn baz<'a>(&'a self) -> impl Foo + 'a {
1527
LL + fn baz(&self) -> impl Foo + '_ {
1628
|
1729

18-
error: aborting due to 1 previous error
30+
error: aborting due to 2 previous errors
1931

tests/ui/extra_unused_lifetimes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,17 @@ mod second_case {
114114
fn hey();
115115
}
116116

117+
// Should lint. The response to the above comment incorrectly called this a false positive. The
118+
// lifetime `'a` can be removed, as demonstrated below.
117119
impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
118120
fn hey() {}
119121
}
122+
123+
struct OtherBox<T: ?Sized>(Box<T>);
124+
125+
impl<T: Source + ?Sized> Source for OtherBox<T> {
126+
fn hey() {}
127+
}
120128
}
121129

122130
// Should not lint

tests/ui/extra_unused_lifetimes.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,11 @@ error: this lifetime isn't used in the function definition
3737
LL | pub fn something<'c>() -> Self {
3838
| ^^
3939

40-
error: aborting due to 6 previous errors
40+
error: this lifetime isn't used in the impl
41+
--> tests/ui/extra_unused_lifetimes.rs:119:10
42+
|
43+
LL | impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
44+
| ^^
45+
46+
error: aborting due to 7 previous errors
4147

tests/ui/needless_lifetimes.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ mod issue2944 {
329329
bar: &'a Bar,
330330
}
331331

332-
impl<'a> Foo for Baz<'a> {}
332+
impl Foo for Baz<'_> {}
333333
impl Bar {
334334
fn baz(&self) -> impl Foo + '_ {
335335
Baz { bar: self }

tests/ui/needless_lifetimes.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ LL - fn needless_lt<'a>(_x: &'a u8) {}
335335
LL + fn needless_lt(_x: &u8) {}
336336
|
337337

338+
error: the following explicit lifetimes could be elided: 'a
339+
--> tests/ui/needless_lifetimes.rs:332:10
340+
|
341+
LL | impl<'a> Foo for Baz<'a> {}
342+
| ^^ ^^
343+
|
344+
help: elide the lifetimes
345+
|
346+
LL - impl<'a> Foo for Baz<'a> {}
347+
LL + impl Foo for Baz<'_> {}
348+
|
349+
338350
error: the following explicit lifetimes could be elided: 'a
339351
--> tests/ui/needless_lifetimes.rs:334:16
340352
|
@@ -564,5 +576,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 {
564576
LL + fn one_input(x: &u8) -> &u8 {
565577
|
566578

567-
error: aborting due to 47 previous errors
579+
error: aborting due to 48 previous errors
568580

0 commit comments

Comments
 (0)