One concern I see with this is that having just one special 'self lifetime actually isn’t enough. You can have arbitrarily many levels of self-referentiality, and each “layer” adds a new, distinct lifetime. Such as:
struct A {
a_val: i32
}
impl Drop for A { ... }
struct B<'a> {
a_ref: &'a A,
b_val: i32,
}
impl<'a> Drop for B<'a> { ... }
struct C<'a, 'b> {
a_ref: &'a A,
b_ref: &'b B,
c_val: i32,
}
impl<'a, 'b> Drop for C<'a, 'b> { ... }
struct SelfRef {
a: A,
b: B<'self>,
c: C<'self, 'self>, /// ???
}
Here there are two distinct “self” lifetimes at play. The one used to denote the lifetime of A, and another for the lifetime of B. They can’t be identical because of dropck. Either the compiler would have to infer this somehow, or we would need to be able to declare multiple special “self” lifetimes.
Even rental can’t handle this yet, and I’ve already had requests to somehow deal with it, since my other lib frequently results in multi-layer borrows like this that one would reasonably want to be able to store in a single struct.