Convert Box<dyn T> to Box<dyn Any>

I understand that this is the case. However, what is the reason to exlude the type-id from the vtable?

The thread linked above gives another use case:

trait A {}
trait B: A {}

fn upcast(x: Box<dyn B>) -> Box<dyn A> {
    panic!("this is not implementable??")
}

For me, the functionality of upcast is useful in some cases. It is frustrating to me that I am unable to comprehend why this is not possible to implement: All information should be there to construct a trait-object of type A from one of type B.

1 Like