diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 693f1b2258745..ae7e965985635 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2639,6 +2639,13 @@ impl LintDiagnostic<'_, G> for ElidedNamedLifetime { 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, diff --git a/tests/ui/async-await/issues/issue-63388-1.stderr b/tests/ui/async-await/issues/issue-63388-1.stderr index 713e4e4dcf5ca..ef74bfe32375e 100644 --- a/tests/ui/async-await/issues/issue-63388-1.stderr +++ b/tests/ui/async-await/issues/issue-63388-1.stderr @@ -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 diff --git a/tests/ui/const-generics/type-dependent/issue-71348.full.stderr b/tests/ui/const-generics/type-dependent/issue-71348.full.stderr index 394259ce55ddb..177ff20fbf9ea 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.full.stderr +++ b/tests/ui/const-generics/type-dependent/issue-71348.full.stderr @@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a >::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 >::Target - | +++ warning: 1 warning emitted diff --git a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr index 0f0d75dbac13e..5aee282952aa2 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -5,10 +5,6 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a >::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 >::Target - | +++ error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:10:24 diff --git a/tests/ui/consts/min_const_fn/min_const_fn.stderr b/tests/ui/consts/min_const_fn/min_const_fn.stderr index 1e88a908af083..4b348a182b87f 100644 --- a/tests/ui/consts/min_const_fn/min_const_fn.stderr +++ b/tests/ui/consts/min_const_fn/min_const_fn.stderr @@ -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 { ... 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` cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:37:25 diff --git a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr index ccea9d5e6e92a..d0f8f7689d17c 100644 --- a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr +++ b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr @@ -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 diff --git a/tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr b/tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr index a60f398684330..50a9f3ebeabb8 100644 --- a/tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr +++ b/tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr @@ -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 diff --git a/tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr b/tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr index 6eea25b4fc8f8..bff3ffd934ac6 100644 --- a/tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr +++ b/tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr @@ -5,10 +5,6 @@ LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator { - | ++ warning: 1 warning emitted diff --git a/tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr b/tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr index 1339c644f5339..f835d2655bb01 100644 --- a/tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr +++ b/tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr @@ -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 diff --git a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr index 144f9454513c5..2d5d4fb0e72ec 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr @@ -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 diff --git a/tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr b/tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr index 834292d103dc8..249ae146b1675 100644 --- a/tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr +++ b/tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr @@ -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 { | -- ^ 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 diff --git a/tests/ui/object-lifetime/object-lifetime-default-elision.stderr b/tests/ui/object-lifetime/object-lifetime-default-elision.stderr index f8ed92111a967..b44a184c6848f 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-elision.stderr +++ b/tests/ui/object-lifetime/object-lifetime-default-elision.stderr @@ -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 diff --git a/tests/ui/self/elision/ignore-non-reference-lifetimes.stderr b/tests/ui/self/elision/ignore-non-reference-lifetimes.stderr index 13cc3a431a5d2..4465dbae52989 100644 --- a/tests/ui/self/elision/ignore-non-reference-lifetimes.stderr +++ b/tests/ui/self/elision/ignore-non-reference-lifetimes.stderr @@ -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 diff --git a/tests/ui/self/self_lifetime-async.stderr b/tests/ui/self/self_lifetime-async.stderr index 2892d790ac7b8..32de3fd18c97f 100644 --- a/tests/ui/self/self_lifetime-async.stderr +++ b/tests/ui/self/self_lifetime-async.stderr @@ -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 diff --git a/tests/ui/self/self_lifetime.stderr b/tests/ui/self/self_lifetime.stderr index ceb0ce345a3eb..cd8f4d8adf8b1 100644 --- a/tests/ui/self/self_lifetime.stderr +++ b/tests/ui/self/self_lifetime.stderr @@ -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 diff --git a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr index 3744dd9f996ce..30f4509d49dee 100644 --- a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr +++ b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr @@ -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 diff --git a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr index baa5fa949ec41..ea01dcd5020cf 100644 --- a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr +++ b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr @@ -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 diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr index 376e58ef9e07e..e2c21f1636b0c 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -7,10 +7,6 @@ LL | fn defining<'a, T>(x: &'a i32) -> Opaque { 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` captures lifetime that does not appear in bounds --> $DIR/missing_lifetime_bound.rs:5:47