Description
We should extend the set of library-defined self types on stable to include types involving ManuallyDrop
. ManuallyDrop
is a transparent wrapper around another type which is completely unconstrained; there should be no technical limitations on making it an dyn-compatible1 receiver type.
To be explicit, I am proposing to make the following types valid self types on stable, and all but the first would be dyn-compatible:
ManuallyDrop<Self>
&ManuallyDrop<Self>
&mut ManuallyDrop<Self>
Box<ManuallyDrop<Self>>
Rc<ManuallyDrop<Self>>
Arc<ManuallyDrop<Self>>
Pin<&ManuallyDrop<Self>>
Pin<&mut ManuallyDrop<Self>>
Pin<Box<ManuallyDrop<Self>>>
Pin<Rc<ManuallyDrop<Self>>>
Pin<Arc<ManuallyDrop<Self>>>
This is similar to but distinct from #56193, which is about making coercions valid involving a manually drop wrapped around a pointer type.
In particular, I am personally interested in having Pin<&mut ManuallyDrop<Self>>
as a dyn-compatible receiver type for an unsafe trait method in my code, as it assists users in understanding the guarantees the caller is giving them - that it will never access or move this value again, even to drop it, do with that what you will.
cc @mikeyhew @rust-lang/lang @rust-lang/wg-unsafe-code-guidelines
Footnotes
-
Formerly known as "object safe". ↩