Arbitrary self types v2: pointers feature gate. by adetaylor · Pull Request #129664 · rust-lang/rust (original) (raw)
This broke crossmist. crossmist needs to serialize and deserialize objects all the time, including Box<dyn Trait>
, sort of like serde_traitobject (after a quick look, that crait likely broke too).
While serializing through dyn Trait
is easy if the trait contains something like a serialize_me
method, deserializing requires somehow creating a valid fat pointer to call a method on from thin air. Both crossmist and serde_traitobject achieve this by storing a vtable pointer prior to object data during serialization, and invoke the virtual method on a dangling fat pointer (with the right vtable) during deserialization.
Crucially, this is only valid if pointers are used, not references, because references can't be dangling or null.
There are ways to workaround this, e.g. by using ZSTs or adding a fn get_deserializing_fn(&self) -> fn(&mut Deserializer) -> Self
function to the trait and prepending the "deserializing fn" to data instead of the vtable. However, all these workarounds introduce indirection and slow code down when really the expected behavior is quite simple.
I think the breakage is going to be more significant than expected and I hope arbitrary_self_types_pointers is not removed.