File tree Expand file tree Collapse file tree 6 files changed +45
-7
lines changed Expand file tree Collapse file tree 6 files changed +45
-7
lines changed Original file line number Diff line number Diff 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
1414impl Bar {
1515 fn baz(&self) -> impl Foo + '_ {
Original file line number Diff line number Diff line change 11error: 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 |
77note: 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 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212help: 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+ |
1426LL - fn baz<'a>(&'a self) -> impl Foo + 'a {
1527LL + fn baz(&self) -> impl Foo + '_ {
1628 |
1729
18- error: aborting due to 1 previous error
30+ error: aborting due to 2 previous errors
1931
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -37,5 +37,11 @@ error: this lifetime isn't used in the function definition
3737LL | 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -335,6 +335,18 @@ LL - fn needless_lt<'a>(_x: &'a u8) {}
335335LL + 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+
338350error: the following explicit lifetimes could be elided: 'a
339351 --> tests/ui/needless_lifetimes.rs:334:16
340352 |
You can’t perform that action at this time.
0 commit comments