Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

we should lint on named lifetimes forced to be equal to another named lifetime #118376

Closed
lcnr opened this issue Nov 27, 2023 · 0 comments · Fixed by #118391
Closed

we should lint on named lifetimes forced to be equal to another named lifetime #118376

lcnr opened this issue Nov 27, 2023 · 0 comments · Fixed by #118391
Assignees
Labels
A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 27, 2023

fn foo<'a, 'b>(x: &'a &'b &'a ()) {} // WARN: `'a` and `'b` are equal

and

fn foo<'a: 'b, 'b: 'a>() {} // WARN: `'a` and `'b` are equal

and

struct Foo<T: 'static>(T);

fn bar<'a>(_: Foo<&'a ()>) {} // WARN: replace `'a` with `'static`

and

struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    fn bar<'b: 'a>(&'b self) {} // WARN: `'a` and `'b` are equal
}

these should all warn that the named lifetimes are equal to some other named lifetime and should be removed.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 27, 2023
@lcnr lcnr changed the title lint on named lifetimes forced to be equal to another named lifetime we should lint on named lifetimes forced to be equal to another named lifetime Nov 27, 2023
@Noratrieb Noratrieb added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-lifetimes Area: lifetime related T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 27, 2023
@compiler-errors compiler-errors self-assigned this Nov 27, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2023
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant

There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures.

Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.

Fixes rust-lang#118376
r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2023
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant

There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures.

Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.

Fixes rust-lang#118376
r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 28, 2023
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant

There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures.

Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.

Fixes rust-lang#118376
r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 29, 2023
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant

There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures.

Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.

Fixes rust-lang#118376
r? lcnr
@bors bors closed this as completed in fa696a3 Apr 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 10, 2024
Rollup merge of rust-lang#118391 - compiler-errors:lifetimes-eq, r=lcnr

Add `REDUNDANT_LIFETIMES` lint to detect lifetimes which are semantically redundant

There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures.

Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.

Fixes rust-lang#118376
r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
4 participants