I have several concerns about all the previous RFCs:
- If 2 lifetimes are provided, is the short lifetime really necessary? (My proposal: no)
- Is it possible store downgradable borrows into something like Vec? (My proposal: no)
- Is it possible that we have to downgrade and upgrade the borrow several times? (My proposal: in the function body,
super 'a value
could be regarded as value itself, thus it could be downgraded many times, or even re-borrow as another super 'b value. At the end of function body, the return value might contains a lifetime which is shorter than super borrow's lifetime.) - How to tell users what could be downgraded and what could not? (My proposal: imagining all the borrow/reborrow/downgrade happens in the same caller. After a mut borrow ends, immutable borrows of-coursely could be created.)
Actually I've made something almost same to your RFC in July 2024. And finally I found that, the borrow could be combined with super-let, since it could be regarded as something occurs on a higher stack.
What's more, I strongly suspect that the short lifetime will cause some corner cases, since it cannot be either enlarged or shorten. For a most simple case, since &'short mut
lives at least 'short
, and we cannot define lifetime shorter than the whole function scope, thus &'short mut
lives for the whole function scope, which makes &'long
cannot be obtained in the function.
fn poc<T>(&<'short mut, 'long> item: T) -> &'long T {
&*item // Can we actually do this?
// firstly, item is borrowed for at least 'short and 'short at least lives here
// which makes &'long impossible to be borrowed.
// thus *item here is *(item as &'short mut), and thus only `&'short T` is generated.
}