struct S<T> {
t: T,
}
// Why is Unpin not automatically implemented for S when I can always
// (regardless of T) implement it manually like this?
impl<T> Unpin for S<T> {}
// By commenting out the previous line we can see that S is not automatically
// Unpin because the following code stops compiling.
fn check_unpin<T>() {
fn use_unpin<T: Unpin>() {}
use_unpin::<S<T>>();
}
If I can trivially make S
Unpin then why is not automatically Unpin?
The Unpin documentation says
This trait is automatically implemented for almost every type.
without specifying the "almost" more.
I think the Unpin-ness of T
does not matter as long we never construct a Pin<T>
. Maybe the compiler is trying to protect me from accidentally making S
!Unpin
with a slight code change (that uses T
in such a way).