Skip to content

Commit 9e2d264

Browse files
committed
Hack around a conflict with clippy::needless_lifetimes
1 parent 547db4a commit 9e2d264

18 files changed

+7
-103
lines changed

compiler/rustc_lint/src/lints.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,13 @@ impl<G: EmissionGuarantee> LintDiagnostic<'_, G> for ElidedNamedLifetime {
26392639
if let Some(declaration) = declaration {
26402640
diag.span_label(declaration, fluent::lint_label_named);
26412641
}
2642+
// FIXME(GrigorenkoPV): this `if` and `return` should be removed,
2643+
// but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
2644+
// https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
2645+
// HACK: `'static` suggestions will never sonflict, emit only those for now.
2646+
if name != rustc_span::symbol::kw::StaticLifetime {
2647+
return;
2648+
}
26422649
match kind {
26432650
MissingLifetimeKind::Underscore => diag.span_suggestion_verbose(
26442651
span,

tests/ui/async-await/issues/issue-63388-1.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ LL | ) -> &dyn Foo
88
| ^ this elided lifetime gets resolved as `'a`
99
|
1010
= note: `#[warn(elided_named_lifetimes)]` on by default
11-
help: consider specifying it explicitly
12-
|
13-
LL | ) -> &'a dyn Foo
14-
| ++
1511

1612
error[E0621]: explicit lifetime required in the type of `foo`
1713
--> $DIR/issue-63388-1.rs:13:5

tests/ui/const-generics/type-dependent/issue-71348.full.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Ta
55
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
66
|
77
= note: `#[warn(elided_named_lifetimes)]` on by default
8-
help: consider specifying it explicitly
9-
|
10-
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
11-
| +++
128

139
warning: 1 warning emitted
1410

tests/ui/const-generics/type-dependent/issue-71348.min.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Ta
55
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
66
|
77
= note: `#[warn(elided_named_lifetimes)]` on by default
8-
help: consider specifying it explicitly
9-
|
10-
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
11-
| +++
128

139
error: `&'static str` is forbidden as the type of a const generic parameter
1410
--> $DIR/issue-71348.rs:10:24

tests/ui/consts/min_const_fn/min_const_fn.stderr

-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ LL | const fn get_lt(&'a self) -> &T { &self.0 }
88
| ^ this elided lifetime gets resolved as `'a`
99
|
1010
= note: `#[warn(elided_named_lifetimes)]` on by default
11-
help: consider specifying it explicitly
12-
|
13-
LL | const fn get_lt(&'a self) -> &'a T { &self.0 }
14-
| ++
1511

1612
warning: elided lifetime has a name
1713
--> $DIR/min_const_fn.rs:48:42
@@ -21,11 +17,6 @@ LL | impl<'a, T> Foo<T> {
2117
...
2218
LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
2319
| ^ this elided lifetime gets resolved as `'a`
24-
|
25-
help: consider specifying it explicitly
26-
|
27-
LL | const fn get_mut_lt(&'a mut self) -> &'a mut T { &mut self.0 }
28-
| ++
2920

3021
error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
3122
--> $DIR/min_const_fn.rs:37:25

tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
1717
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
1818
|
1919
= note: `#[warn(elided_named_lifetimes)]` on by default
20-
help: consider specifying it explicitly
21-
|
22-
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
23-
| ~~
2420

2521
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
2622
--> $DIR/impl-fn-hrtb-bounds.rs:4:41

tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
55
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
66
|
77
= note: `#[warn(elided_named_lifetimes)]` on by default
8-
help: consider specifying it explicitly
9-
|
10-
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + 'a) {
11-
| ~~
128

139
error[E0792]: expected generic lifetime parameter, found `'_`
1410
--> $DIR/impl-fn-predefined-lifetimes.rs:7:9

tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item =
55
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
66
|
77
= note: `#[warn(elided_named_lifetimes)]` on by default
8-
help: consider specifying it explicitly
9-
|
10-
LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &'a u32)> {
11-
| ++
128

139
warning: 1 warning emitted
1410

tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ LL | fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
114114
| lifetime `'a` declared here
115115
|
116116
= note: `#[warn(elided_named_lifetimes)]` on by default
117-
help: consider specifying it explicitly
118-
|
119-
LL | fn m<'a>(_: &'a Foo<'a>) -> &'a str { "" }
120-
| ++
121117

122118
error: aborting due to 7 previous errors; 1 warning emitted
123119

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
77
| lifetime `'a` declared here
88
|
99
= note: `#[warn(elided_named_lifetimes)]` on by default
10-
help: consider specifying it explicitly
11-
|
12-
LL | fn foo<'a>(&'a self, x: &i32) -> &'a i32 {
13-
| ++
1410

1511
error[E0621]: explicit lifetime required in the type of `x`
1612
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:9:36

tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr

-19
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ note: the lint level is defined here
1111
|
1212
LL | #![deny(elided_named_lifetimes)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^
14-
help: consider specifying it explicitly
15-
|
16-
LL | fn ampersand<'a>(x: &'a u8) -> &'a u8 {
17-
| ++
1814

1915
error: elided lifetime has a name
2016
--> $DIR/missing-lifetime-kind.rs:10:31
@@ -23,11 +19,6 @@ LL | fn brackets<'a>(x: &'a u8) -> Brackets {
2319
| -- ^^^^^^^^ this elided lifetime gets resolved as `'a`
2420
| |
2521
| lifetime `'a` declared here
26-
|
27-
help: consider specifying it explicitly
28-
|
29-
LL | fn brackets<'a>(x: &'a u8) -> Brackets<'a> {
30-
| ++++
3122

3223
error: elided lifetime has a name
3324
--> $DIR/missing-lifetime-kind.rs:17:33
@@ -36,11 +27,6 @@ LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
3627
| -- ^ this elided lifetime gets resolved as `'a`
3728
| |
3829
| lifetime `'a` declared here
39-
|
40-
help: consider specifying it explicitly
41-
|
42-
LL | fn comma<'a>(x: &'a u8) -> Comma<'a, u8> {
43-
| +++
4430

4531
error: elided lifetime has a name
4632
--> $DIR/missing-lifetime-kind.rs:22:34
@@ -49,11 +35,6 @@ LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
4935
| -- ^^ this elided lifetime gets resolved as `'a`
5036
| |
5137
| lifetime `'a` declared here
52-
|
53-
help: consider specifying it explicitly
54-
|
55-
LL | fn underscore<'a>(x: &'a u8) -> &'a u8 {
56-
| ~~
5738

5839
error: aborting due to 4 previous errors
5940

tests/ui/object-lifetime/object-lifetime-default-elision.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ LL | fn load2<'a>(ss: &'a dyn SomeTrait) -> &dyn SomeTrait {
77
| lifetime `'a` declared here
88
|
99
= note: `#[warn(elided_named_lifetimes)]` on by default
10-
help: consider specifying it explicitly
11-
|
12-
LL | fn load2<'a>(ss: &'a dyn SomeTrait) -> &'a dyn SomeTrait {
13-
| ++
1410

1511
error: lifetime may not live long enough
1612
--> $DIR/object-lifetime-default-elision.rs:73:5

tests/ui/self/elision/ignore-non-reference-lifetimes.stderr

-9
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ LL | fn a<'a>(self: Self, a: &'a str) -> &str {
55
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
66
|
77
= note: `#[warn(elided_named_lifetimes)]` on by default
8-
help: consider specifying it explicitly
9-
|
10-
LL | fn a<'a>(self: Self, a: &'a str) -> &'a str {
11-
| ++
128

139
warning: elided lifetime has a name
1410
--> $DIR/ignore-non-reference-lifetimes.rs:10:44
1511
|
1612
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &str {
1713
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
18-
|
19-
help: consider specifying it explicitly
20-
|
21-
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &'a str {
22-
| ++
2314

2415
warning: 2 warnings emitted
2516

tests/ui/self/self_lifetime-async.stderr

-9
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ LL | async fn foo<'b>(self: &'b Foo<'a>) -> &() { self.0 }
77
| lifetime `'b` declared here
88
|
99
= note: `#[warn(elided_named_lifetimes)]` on by default
10-
help: consider specifying it explicitly
11-
|
12-
LL | async fn foo<'b>(self: &'b Foo<'a>) -> &'b () { self.0 }
13-
| ++
1410

1511
warning: elided lifetime has a name
1612
--> $DIR/self_lifetime-async.rs:12:52
1713
|
1814
LL | async fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
1915
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
20-
|
21-
help: consider specifying it explicitly
22-
|
23-
LL | async fn bar<'a>(self: &Alias, arg: &'a ()) -> &'a () { arg }
24-
| ++
2516

2617
warning: 2 warnings emitted
2718

tests/ui/self/self_lifetime.stderr

-9
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ LL | fn foo<'b>(self: &'b Foo<'a>) -> &() { self.0 }
77
| lifetime `'b` declared here
88
|
99
= note: `#[warn(elided_named_lifetimes)]` on by default
10-
help: consider specifying it explicitly
11-
|
12-
LL | fn foo<'b>(self: &'b Foo<'a>) -> &'b () { self.0 }
13-
| ++
1410

1511
warning: elided lifetime has a name
1612
--> $DIR/self_lifetime.rs:13:46
1713
|
1814
LL | fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
1915
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
20-
|
21-
help: consider specifying it explicitly
22-
|
23-
LL | fn bar<'a>(self: &Alias, arg: &'a ()) -> &'a () { arg }
24-
| ++
2516

2617
warning: 2 warnings emitted
2718

tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &T) {
131131
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
132132
|
133133
= note: `#[warn(elided_named_lifetimes)]` on by default
134-
help: consider specifying it explicitly
135-
|
136-
LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &'a T) {
137-
| ++
138134

139135
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
140136
--> $DIR/impl-trait-missing-lifetime-gated.rs:6:35

tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ LL | fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + '_ + 'a
1313
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
1414
|
1515
= note: `#[warn(elided_named_lifetimes)]` on by default
16-
help: consider specifying it explicitly
17-
|
18-
LL | fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a + 'a
19-
| ~~
2016

2117
error[E0700]: hidden type for `impl FnOnce()` captures lifetime that does not appear in bounds
2218
--> $DIR/missing-lifetimes-in-signature.rs:19:5

tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
77
| lifetime `'a` declared here
88
|
99
= note: `#[warn(elided_named_lifetimes)]` on by default
10-
help: consider specifying it explicitly
11-
|
12-
LL | fn defining<'a, T>(x: &'a i32) -> Opaque<'a, T> { x }
13-
| +++
1410

1511
error[E0700]: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
1612
--> $DIR/missing_lifetime_bound.rs:5:47

0 commit comments

Comments
 (0)