rust-lang / rust-lang/rust-clippy

Separate lint needless_lifetimes for types with multiple lifetimes

Open
#12,495 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by locating the existing needless_lifetimes lint and its tests, then determine the intended boundary for types with multiple lifetimes and whether a separate lint or an exemption is preferable; done means the behavior and user-facing lint configuration are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.