Interesting!
Just a note: I did choose the most cautious approach for my API: taking ownership of a value of type T (which we could #[inline(always)] to hint at avoiding the copy), and then lending a &'a mut T for any 'a where T : 'a. I’m pretty sure this is not only currently sound, but sound even with regards to other patterns. Please correct me if I am wrong!
The elephant in the room here, to which @RalfJung’s post was directed (I think), is if instead of
trait WithDiverging<'a> : Sized + 'a {
fn with_diverging (
self,
f: impl FnOnce(&'a mut Self) -> Diverging,
) -> !
we had
trait WithDiverging<'a> : 'a {
fn with_diverging (
&'_ mut self,
f: impl FnOnce(&'a mut Self) -> Diverging,
) -> ! // this function **never** returns (AbortOnDrop guard)
it does seem like it should be sound, by agree that it may break other subtle stuff.
EDIT: s/Fn/FnOnce/g