Description
Originally posted by @Ekleog in #65991 (comment)
I just tried using this feature to upcast to Any + Send + Sync
, and it seems to me like this is currently not allowed:
trait DynSized: 'static + Any + Send + Sync + DeepSizeOf {}
impl<T: 'static + Any + Send + Sync + DeepSizeOf> DynSized for T {}
fn main() {
let ptr = Arc::new(()) as Arc<dyn DynSized>;
let ptr_any = ptr as Arc<dyn Any + Send + Sync>;
// my goal:
let res = Arc::<dyn Any + Send + Sync>::downcast::<()>(ptr);
}
With references, the situation does not seem better than with Arc
: this does not compile either
fn main() {
let ptr = &() as &'static dyn DynSized;
let ptr_any = ptr as &'static (dyn Any + Send + Sync);
}
Is this expected? I can't find any reference to this limitation, neither explicitly in the RFC text nor in this tracking issue. The RFC text does mention not supporting upcasting to multiple traits, but I'd have expected lifetimes as well as auto traits to not be included in the limitation.
If it is expected that this feature is stabilized without this support, does anyone know where I should watch, to know of the news on that front?
Minimized:
trait Source: Send + Target {}
fn upcast(x: &dyn Source) -> &(dyn Target + Send) { x }
We should be able to upcast to a dyn type w/ auto-traits that show up in the principal's supertraits too.