rust-lang / rust-lang/rust-clippy
New lint: Warn against lifetimes being the same, e.g. `'a: 'b, 'b: 'a`
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
Lint against lifetime arguments that come with bounds making them equal.
For example
fn foo<'a: 'b, 'b: 'a>(x: &'a (), y: &'b ()) {}
could be written
fn foo<'a>(x: &'a (), y: &'a ()) {}
Most notably this lint must also be able to take implied bound into consideration, e.g.
fn foo<'a: 'b, 'b>(x: &'a &'b ()) {}
For some background: I came across this question on URLO; I'm unhappy that neither the Rust compiler nor clippy would be pointing out the problem I pointed out in my answer, even though it's obvious that two lifetimes in question are only accidentally restricted to be equal.
Categories
- Kind: Not quite sure, possibly
suspicions, or at leastcomplexity.
What is the advantage of the recommended code over the original code
Shorter, more clear; catches some cases where you're having unnecessary bounds or misdesigned an API
Drawbacks
Probably none?
I'm not sure under what conditions the lint should fire in trait impls. I suppose there would be cases where bounds from a trait impl and a trait method can end up restricting two lifetimes to be the same without there being a way to avoid it? (I don't have an example (yet) though...)
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
No source files, tests, or entry points are named. Start by examining the lifetime-bound examples and the linked URLO discussion, then resolve how implied bounds and trait impls should affect the lint. Done means the lint behavior and its applicability are defined for the stated cases.
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
- 35/100