Skip to content

A lint to detect explicitly-annotated lifetimes which can be inferred #18853

Closed
@bstrie

Description

@bstrie

I think a lint for code of the following form would be useful:

fn foo<'a>(x: &'a str) -> &'a str {
    x
}

This function signature contains explicit lifetimes which can be inferred by the compiler. I imagine that the lint would emit something like the following:

warning: unnecesary lifetime annotations
fn foo<'a>(x: &'a str) -> &'a str {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: signature can be written as follows:
fn foo(x: &str) -> &str {

Perhaps the suggested signature bit would be tricky. I also have no opinion regarding whether or not this lint would be on or off by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions