Can unsafe smart pointer downcasts be correct?

There was some discussion on whether Box::<dyn Any>::downcast_unchecked should instead be Box::<impl ?Sized>::cast_unchecked, which if applied to Arcs API too would allow this:

My feeling is that CoerceUnsized does force this to be valid, since there is no code run during the coercion there's no way Arc could make it invalid; but I don't know that there's enough documentation about what unsizing-coercions do to actually make that a firm guarantee.

2 Likes