So I just had a conversation with @wycats. We elaborated on “the syntax table”, and we also had the insight that – as a general rule – if you have an &Foo
, we can still completely allow eliding any lifetime parameters of Foo
, since there is already an indication of borrowing from the outer &
(this was the same argument that I used to claim we would not need to ever write &Foo&
).
// Not eliding 'nested lifetimes' like `'a` in `&Foo<'a>`
Foo' Foo'<T> &Foo' &Foo'<T>
Foo& Foo&<T> &Foo& &Foo<T>
Foo<'> Foo<', T> &Foo<'> &Foo<', T>
Foo<&> Foo<&, T> &Foo<&> &Foo<&, T>
Foo<ref> Foo<ref, T> &Foo<ref, T> &Foo<ref, T>
// Eliding 'nested lifetimes' like `'a` in `&Foo<'a>`
Foo' Foo'<T> &Foo &Foo<T>
Foo& Foo&<T> &Foo &Foo<T>
Foo<'> Foo<', T> &Foo &Foo<T>
Foo<&> Foo<&, T> &Foo &Foo<T> // my preference
Foo<ref> Foo<ref, T> &Foo<T> &Foo<T>
When I look at these syntaxes, particularly the second set, I feel like Foo<&>
stands out to me as the best choice:
- we have the consistency of
&
as the “elidable lifetime”- when first learning, you can probably get quite far this way
- using the angle brackets, like
Foo<&>
, strongly reads to me as “struct with references in it”, which is precisely what it is- that is, we do not have the
&Foo
vsFoo&
confusion
- that is, we do not have the
- we do not have the “floating single tick” syntax (
'
) that is very surprising and provokes strong reaction in some people- we also avoid “doubling down on the tick”
The only case in that table that kind of “looks heavy” to me Foo<&, T>
– but it’s also one of the cases where I personally get confused about today (because you can elide the &
). (Well, I sometimes get confused about &Foo<T>
, but I think the ongoing work on improved lifetime errors will solve this.) It feels like this comes up rarely to me in practice; it’d be interesting to try and measure it.
I agree that there is a nice continuity between Foo<', T>
and Foo<'a, T>
, but it feels like it is compensated for by the twin downsides of:
- single tick alone is very jarring to some people
-
lack of continuity between
&T
andFoo<&>