Skip to content

Separate lint needless_lifetimes for types with multiple lifetimes #12495

Open
@antoyo

Description

@antoyo

What it does

I'd like to propose to make the lint needless_lifetimes only warn for references (and possibly types with a single lifetime) and add a new separate lint like needless_lifetimes, but that warns for types with multiple lifetimes (where at least one could be elided).

An alternative could to be not warn about needless_lifetimes when the lifetimes contain multiple characters (like 'stuff).

Advantage

For types with multiple lifetimes, it might help readability to keep the lifetimes in the code even if they could be elided.
So, by having a new separate lint, users who prefer to keep lifetimes on types with multiple lifetimes, they could disable this new lint and keep the ability to get warned about needless_lifetimes for simple cases.

Drawbacks

None since the choice would be up to the user.

Example

struct Test<'a, 'b> {
    a: &'a i32,
    b: &'b i32,
}

fn test<'a, 'b>(test: Test<'a, 'b>) -> &'a i32 {
    test.a
}

Could be written as:

fn test<'a>(test: Test<'a, '_>) -> &'a i32 {
    test.a
}

Metadata

Metadata

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