Skip to content

Detect named lifetimes that are effectively 'static #10108

Open
@estebank

Description

@estebank

What it does

Given a function that returns a borrow to a lifetime that isn't used in any parameter, give and explanation and suggest removing the named lifetime and making it 'static, as it is the only effective lifetime that will work:

fn foo<'a>() -> &'a str { todo!() }

Lint Name

hidden_static_lifetime

Category

suspicious, style, pedantic

Advantage

It makes the code easier to follow and is a good thing to teach users about.

Drawbacks

No response

Example

fn foo<'a>() -> &'a str { todo!() }

Could be written as:

fn foo() -> &'static str { todo!() }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions