You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
When writing data structures using unsafe code or otherwise unused type parameters, library authors often reach for PhantomData<T> without adequate consideration.
You might have missed it (as the standard library did too) that PhantomData<T> is not the right phantom type here. For the empty iterator the phantom type should be Send and Sync regardless of whether T is Send and Sync, as no T ever exists.
The canonical covariant-always-Send-and-Sync type in the standard library is fn() -> T so a library author who realizes PhantomData<T> is not right would write:
pubstructIterEmpty<T>(PhantomData<fn() -> T>);
This is still a bad choice because function pointers can't exist under the conservative const fn feature gate.
I want a library for emitting correct const-compatible phantom types (like the last correct solution above) that puts variance and autotrait behavior front and center for readers and reviewers.