Hack around a conflict with clippy::needless_lifetimes

This commit is contained in:
Pavel Grigorenko 2024-09-01 16:49:55 +03:00
parent 547db4a4b7
commit 9e2d264fa2
18 changed files with 7 additions and 103 deletions

View File

@ -2639,6 +2639,13 @@ fn decorate_lint(self, diag: &mut rustc_errors::Diag<'_, G>) {
if let Some(declaration) = declaration {
diag.span_label(declaration, fluent::lint_label_named);
}
// FIXME(GrigorenkoPV): this `if` and `return` should be removed,
// but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
// https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
// HACK: `'static` suggestions will never sonflict, emit only those for now.
if name != rustc_span::symbol::kw::StaticLifetime {
return;
}
match kind {
MissingLifetimeKind::Underscore => diag.span_suggestion_verbose(
span,

View File

@ -8,10 +8,6 @@ LL | ) -> &dyn Foo
| ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | ) -> &'a dyn Foo
| ++
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/issue-63388-1.rs:13:5

View File

@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Ta
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
| +++
warning: 1 warning emitted

View File

@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Ta
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
| +++
error: `&'static str` is forbidden as the type of a const generic parameter
--> $DIR/issue-71348.rs:10:24

View File

@ -8,10 +8,6 @@ LL | const fn get_lt(&'a self) -> &T { &self.0 }
| ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | const fn get_lt(&'a self) -> &'a T { &self.0 }
| ++
warning: elided lifetime has a name
--> $DIR/min_const_fn.rs:48:42
@ -21,11 +17,6 @@ LL | impl<'a, T> Foo<T> {
...
LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
| ^ this elided lifetime gets resolved as `'a`
|
help: consider specifying it explicitly
|
LL | const fn get_mut_lt(&'a mut self) -> &'a mut T { &mut self.0 }
| ++
error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:37:25

View File

@ -17,10 +17,6 @@ LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
| ~~
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
--> $DIR/impl-fn-hrtb-bounds.rs:4:41

View File

@ -5,10 +5,6 @@ LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + 'a) {
| ~~
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/impl-fn-predefined-lifetimes.rs:7:9

View File

@ -5,10 +5,6 @@ LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item =
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &'a u32)> {
| ++
warning: 1 warning emitted

View File

@ -114,10 +114,6 @@ LL | fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn m<'a>(_: &'a Foo<'a>) -> &'a str { "" }
| ++
error: aborting due to 7 previous errors; 1 warning emitted

View File

@ -7,10 +7,6 @@ LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn foo<'a>(&'a self, x: &i32) -> &'a i32 {
| ++
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:9:36

View File

@ -11,10 +11,6 @@ note: the lint level is defined here
|
LL | #![deny(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying it explicitly
|
LL | fn ampersand<'a>(x: &'a u8) -> &'a u8 {
| ++
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:10:31
@ -23,11 +19,6 @@ LL | fn brackets<'a>(x: &'a u8) -> Brackets {
| -- ^^^^^^^^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
help: consider specifying it explicitly
|
LL | fn brackets<'a>(x: &'a u8) -> Brackets<'a> {
| ++++
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:17:33
@ -36,11 +27,6 @@ LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
help: consider specifying it explicitly
|
LL | fn comma<'a>(x: &'a u8) -> Comma<'a, u8> {
| +++
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:22:34
@ -49,11 +35,6 @@ LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
| -- ^^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
help: consider specifying it explicitly
|
LL | fn underscore<'a>(x: &'a u8) -> &'a u8 {
| ~~
error: aborting due to 4 previous errors

View File

@ -7,10 +7,6 @@ LL | fn load2<'a>(ss: &'a dyn SomeTrait) -> &dyn SomeTrait {
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn load2<'a>(ss: &'a dyn SomeTrait) -> &'a dyn SomeTrait {
| ++
error: lifetime may not live long enough
--> $DIR/object-lifetime-default-elision.rs:73:5

View File

@ -5,21 +5,12 @@ LL | fn a<'a>(self: Self, a: &'a str) -> &str {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn a<'a>(self: Self, a: &'a str) -> &'a str {
| ++
warning: elided lifetime has a name
--> $DIR/ignore-non-reference-lifetimes.rs:10:44
|
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &str {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
help: consider specifying it explicitly
|
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &'a str {
| ++
warning: 2 warnings emitted

View File

@ -7,21 +7,12 @@ LL | async fn foo<'b>(self: &'b Foo<'a>) -> &() { self.0 }
| lifetime `'b` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | async fn foo<'b>(self: &'b Foo<'a>) -> &'b () { self.0 }
| ++
warning: elided lifetime has a name
--> $DIR/self_lifetime-async.rs:12:52
|
LL | async fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
help: consider specifying it explicitly
|
LL | async fn bar<'a>(self: &Alias, arg: &'a ()) -> &'a () { arg }
| ++
warning: 2 warnings emitted

View File

@ -7,21 +7,12 @@ LL | fn foo<'b>(self: &'b Foo<'a>) -> &() { self.0 }
| lifetime `'b` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn foo<'b>(self: &'b Foo<'a>) -> &'b () { self.0 }
| ++
warning: elided lifetime has a name
--> $DIR/self_lifetime.rs:13:46
|
LL | fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
help: consider specifying it explicitly
|
LL | fn bar<'a>(self: &Alias, arg: &'a ()) -> &'a () { arg }
| ++
warning: 2 warnings emitted

View File

@ -131,10 +131,6 @@ LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &T) {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &'a T) {
| ++
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:6:35

View File

@ -13,10 +13,6 @@ LL | fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + '_ + 'a
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a + 'a
| ~~
error[E0700]: hidden type for `impl FnOnce()` captures lifetime that does not appear in bounds
--> $DIR/missing-lifetimes-in-signature.rs:19:5

View File

@ -7,10 +7,6 @@ LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
LL | fn defining<'a, T>(x: &'a i32) -> Opaque<'a, T> { x }
| +++
error[E0700]: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
--> $DIR/missing_lifetime_bound.rs:5:47