Add a new mismatched-lifetime-syntaxes
lint by shepmaster · Pull Request #138677 · rust-lang/rust (original) (raw)
That enum was added recently by you as part of this same work
Yes. The only reason it's not part of this PR is that it was blocking other compiler contributors and was extracted to a separate PR. I link to it as a listing of the choices available, not to prove its authoritativeness.
one of those continually confusing areas where the compiler and the lang team / Reference disagree about terminology
I see the point and wish there were not confusion, but there are two related yet different concepts:
- What the user typed / what the source code shows (what I'm calling "syntax")
- The higher-level meaning (what I'm calling "style")
I assert that using the same name for the syntax of &T
and &'_ T
will likely be confusing to users 1 and will almost certainly be confusing to compiler developers. That's why I've chosen the implementation path of having the two enums (LifetimeSyntax
, LifetimeSource
) as the primary representation through the compiler and restricted the confusing meaning to the lint.
User-facing parts of the lint (the documentation, lint messages) should indeed use the lang-team-decided terminology of named/elided/hidden where needed.
For my own part (which I don't think I've done a good job expressing), I think that saying that fn x(&u8) -> ContainsLifetime
has one "elided lifetime" and one "hidden lifetime" when the action of lifetime elision occurs equally for both will already confuse users 2.
I'd prefer we find a way to avoid that and to either use the same terms to mean the same things or, if we can't align our concepts, at least to use non-overlapping terms.
That would be wonderful, but I'm not seeing how to align the terms completely because of the intrinsic differences. The source code allows for the product of {Reference, Path} ✕ {NoSyntax, AnonymousLifetime, NamedLifetime}
but meaning-wise we group it as
(Reference, NoSyntax)
/(Reference, AnonymousLifetime)
/(Path, AnonymousLifetime)
("elided")(Path, NoSyntax)
("hidden")(Reference, NamedLifetime)
/(Path, NamedLifetime)
("named")
At least until the HIR level, I argue that the compiler should correspond to what the user entered.