Lint on overly-complex lifetime annotations when lifetime subtyping would handle it
Open
Nobody has claimed this yet.
A-lifetimes
A-lints
C-feature-request
T-lang
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
A common mistake for beginners writing lifetime annotations is to write something like this:
pub fn min<'a: 'c, 'b: 'c, 'c, T: Ord>(a: &'a T, b: &'b T) -> &'c T {
if b < a { b } else { a }
}
which while it's not wrong, is rather more complex than necessary.
It would be nice for the compiler to use its own knowledge of subtyping to suggest that the signature change to
pub fn min<'c, T: Ord>(a: &'c T, b: &'c T) -> &'c T {
if b < a { b } else { a }
}
since that's equivalent.
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 file, test, or compiler entry point is named. Use the two min signatures as the acceptance example while locating the relevant lifetime-subtyping diagnostic path; done means the more complex annotation produces a clear suggestion to use the equivalent shared lifetime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100