Skip to content

Commit

Permalink
Hack around a conflict with clippy::needless_lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Sep 6, 2024
1 parent 547db4a commit 9e2d264
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 103 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,13 @@ impl<G: EmissionGuarantee> 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,
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/async-await/issues/issue-63388-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 0 additions & 4 deletions tests/ui/const-generics/type-dependent/issue-71348.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions tests/ui/consts/min_const_fn/min_const_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/impl-trait/impl-fn-predefined-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions tests/ui/lint/elided-named-lifetimes/missing-lifetime-kind.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions tests/ui/self/elision/ignore-non-reference-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 0 additions & 9 deletions tests/ui/self/self_lifetime-async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 0 additions & 9 deletions tests/ui/self/self_lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 0 additions & 4 deletions tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e2d264

Please sign in to comment.