rust-lang / rust-lang/rust-analyzer
Inlay Hints for lifetimes
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Inlay hints automatically display inferred types has made it significantly easier to see what is happening to what in a program.
This has also been very helpful to understand how some libraries are working.
Rust can most often infer the type of a variable within a function, so a plain source code does not need to be explicit at every corner, but hints provide a much needed insight to what can be done next.
However, types are only half of the story with Rust, as the borrow checker also relies on lifetimes to confirm correctness. Most of the time, those lifetimes are elided, making it easy to believe they are not there. This illusion breaks when some refactors go outside the elision rules, requiring the programmer to explicitly annotate them.
Lifetimes in Rust are a tricky part that scares many beginners, as it is not a common concept found in other languages (even though the mechanics can be understood fairly easily), causing many cases to shy away from a much needed change.
I believe it would be helpful to see the elided lifetime information of the variable along with the type hints.
This could help learners in getting more familiar with the feature, and inform refactors of the actual lifetime that was in use originally.
As a downside however, adding lifetime information could also create a lot of noise, as it is expected they would be bound to the same scope most of the time. This might require setting a more fine-grained control of what to include in inlay hints to opt in or out of showing lifetimes.
I wouldn't be surprised there has been some discussion about this already, but couldn't find any information on the status of such a project.
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 proposes displaying inferred lifetime information alongside existing type inlay hints, with possible fine-grained controls for noise. No files, tests, or implementation entry points are named; begin by locating the current inlay-hints implementation and its configuration, then define the supported lifetime displays and opt-in or opt-out behavior. Done means lifetime hints appear correctly and their presentation can be controlled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100