I am confused about the requirement of Pin<P> that
a value, once pinned, must remain pinned forever.
I saw the discussion thread on reddit but after reading through it I remain confused.
To me, it feels more natural if we require the pointee to be pinned when the Pin<P> object is alive, but can re-acquire the ability to move it again after the Pin<P> object is dropped.
As a concrete example,
use std::mem;
use std::pin::Pin;
fn move_pinned_ref<T>(mut a: T, mut b: T) {
unsafe {
let p: Pin<&mut T> = Pin::new_unchecked(&mut a);
// *I prefer* it to mean that the pointee `a` cannot move when `p` is in the scope.
// But *actually* it means the pointee `a` can never move again.
}
mem::swap(&mut a, &mut b);
// *I prefer* it to be valid because `p` has been dropped.
// But we *actually* have violated the pinning API contract that a value,
// once pinned, must remain pinned forever.
}
Can someone please point out why the design I prefer is problematic?