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

Suggest unused lifetime parameters #119236

Open
mu001999 opened this issue Dec 23, 2023 · 2 comments
Open

Suggest unused lifetime parameters #119236

mu001999 opened this issue Dec 23, 2023 · 2 comments
Labels
A-lifetimes Area: Lifetimes / regions A-lints 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.

Comments

@mu001999
Copy link
Contributor

mu001999 commented Dec 23, 2023

Code

type Foo<'a> = ();

fn foo<'a>() -> Foo<'a> { () }

fn main() {
    foo();
}

Current output

Success

Desired output

warning: lifetime parameter `'a` is never used
 --> src/main.rs:1:10
  |
1 | type Foo<'a> = ();
  |          ^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: lifetime parameter `'a` is never used
 --> src/main.rs:3:8
  |
3 | fn foo<'a>() -> Foo<'a> { () }
  |        ^^

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@mu001999 mu001999 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 23, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 23, 2023
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-lifetimes Area: Lifetimes / regions C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed A-diagnostics Area: Messages for errors, warnings, and lints needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 23, 2024
@fmease
Copy link
Member

fmease commented Jan 23, 2024

This is only tangentially related but the specific code you posted will stop compiling anyway once lazy type aliases (#112792) become the default in Rust 202X:

error[E0392]: parameter `'a` is never used
 --> src/main.rs:3:10
  |
3 | type Foo<'a> = ();
  |          ^^ unused parameter
  |
  = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

@sanxiyn
Copy link
Member

sanxiyn commented Feb 27, 2024

Note that Clippy already has a warning about this.

fn foo<'a>() {}

fn main() {
    foo();
}
warning: this lifetime isn't used in the function definition
 --> src/main.rs:1:8
  |
1 | fn foo<'a>() {}
  |        ^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
  = note: `#[warn(clippy::extra_unused_lifetimes)]` on by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-lints 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.
Projects
None yet
Development

No branches or pull requests

4 participants