Description
I'm referring to https://github.com/fkoep/downcast-rs/blob/master/src/lib.rs#L107-L117
One thing that seems scary, is it's relying on the internal layout of https://doc.rust-lang.org/std/raw/struct.TraitObject.html . This is nightly specifically because it's not stable (See rust-lang/rust#27751 ) , so if the layout were to change for whatever reason (However unlikely) it would probably break this horribly (And what's more, it would probably work fine on some compiler versions but not others, and possibly not break with just a guaranteed panic but with memory-unsafety/UB).
The assert assert_eq!(mem::size_of::<&T>(), mem::size_of::<TraitObject>());
doesn't feel sufficient to me to guarantee that what is being done is safe. If I recall correctly, slices references(Which satisfy the :?Sized check) have the same size but mean a completely different thing.
Nemo157 on the community discord's #black-magic channel pointed out TraitObject
also must be repr(C) for there to be any layout guarantees about it (Reordering, etc).