rust-lang / rust-lang/rust-clippy
Separate lint needless_lifetimes for types with multiple lifetimes
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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