rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.07k stars 1.57k forks source link

Inlay hint for `elided-lifetimes-in-paths` #18007

Open Ten0 opened 2 weeks ago

Ten0 commented 2 weeks ago

Rust proposes a warning for elided-lifetimes-in-paths, because "Elided lifetime parameters can make it difficult to see at a glance that borrowing is occurring. This lint ensures that lifetime parameters are always explicitly stated, even if it is the '_ placeholder lifetime."

Enabling this disabled-by-default warning makes sure that the code is always readable on that regard, but it looks like having that as an inlay hint instead of enabling the lint to enforce on each developer that they set them, may give the readability benefit without the downside of having to actually write them and/or add/remove them everywhere when adding/removing lifetimes to the struct.

Does that look like something that would be reasonable to add to rust-analyzer?

Veykril commented 2 weeks ago

We already have inlay hints for lifetime elision, but they don't yet work for path lifetime params (only refs). We do want to have that work there as well.

Ten0 commented 2 weeks ago

I find inlay hints for ellided lifetimes ('0, '1,...) for passed references otherwise generally polluting: unlike ellided lifetimes in paths, it's still obvious that there's a lifetime involved, because of the &, so I don't enable them.

This feature request is specifically looking to get a <'_> inlay hint on the parameters as the elided-lifetimes-in-paths lint suggests to write, without enabling all lifetime hints and adding tons of generic lifetime parameters and explicit lifetime annotations.

Does it look like it would be reasonable to allow enabling one but not the other?

Veykril commented 2 weeks ago

They can be quite noisy (hence why they are disabled by default), and having them all enabled is generally only useful for teaching imo (if they worked in all occasions that is). Otherwise right now they are only mainly useful with skip_trivial enabled, in which case they are only rendered when there is an output using a lifetime to see which input its tied to. Having them only work path lifetimes as a config seems reasonable to me as well.