Closed as not planned
Description
The safe constructor Pin::new(pointer: Ptr)
restricts the pointed object with the Unpin
trait. However, this restriction can be bypassed using the literal constructor of Pin
or the pin!
macro.
Why not prevent this by making the literal constructor private and modifying the pin!
macro as follows?
pub struct Pin<Ptr> {
__pointer: Ptr,
}
macro_rules! safe_pin {
($value:expr) => {
Pin::<&mut _>::new(&mut $value)
};
}
To the best of my knowledge, the side effect is that API users can no longer create a Pin
object using pin!
if the object does not implement Unpin
. However, developers can still use Pin::new_unchecked(pointer: Ptr)
to achieve the same result. More importantly, I believe unsoundness must not be tolerated in safe Rust.