Skip to content

"warning: unnecessary lifetime parameter" unsilenceable lint #96956

Description

@ijackson

Given the following code:

pub fn thing<'a>(_s: &'a str) where 'a: 'static { }

The current output is:

warning: unnecessary lifetime parameter `'a`
 --> src/lib.rs:2:37
  |
2 | pub fn thing<'a>(_s: &'a str) where 'a: 'static { }
  |                                     ^^
  |
  = help: you can use the `'static` lifetime directly, in place of `'a`

warning: `playground` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 1.27s

Ideally the output should also say something like this:

  = note: `#[warn(needless_lifetimes)]` on by default

And of course then #[allow(needless_lifetimes)] ought to work.

Versions affected

rustcargo@zealot:/volatile/rustcargo/Rustup/Game/server$ rustc -vV
rustc 1.62.0-nightly (ecd44958e 2022-05-10)
binary: rustc
commit-hash: ecd44958e0a21110d09862ee080d95a4ca6c52f8
commit-date: 2022-05-10
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1
rustcargo@zealot:/volatile/rustcargo/Rustup/Game/server$ 

The example code is accepted without any complaint by stable and beta, However, in both stable and beta, clippy has the same weird name-less complaint. And saying #![allow(clippy::needless_lifetimes)] doesn't suppress the message.

I searched for "lifetime" in the clippy lints db. Of those that came up, needless_lifetimes and redundant_static_lifetimes seemed like they might be it, but neither of those suppresses the lint on stable's clippy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions