You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected this code to compile with Rust 1.86, given the new upcasting support.
Instead, the compiler gives E0277.
Why should this code now work? Self must be either:
A (Sized) concrete type implementing Foo, or
A (!Sized) trait object type of Foo or some subtrait thereof.
In either case, it should now be possible to cast to a Foo trait object, but the compiler is not allowing it yet. It's
like some part of the upcasting support is missing.
The problem occurs with stable 1.86. As of time of writing, the problem still occurs with nightly (1.88).
I think I understand: not all !Sized types are trait objects, so there is a 3rd case, where trait upcasting does not work.
To code up your counter-example:
traitFoo{fntrait_obj(&self) -> &dynFoo;}impl<T>Foofor[T]{fntrait_obj(&self) -> &dynFoo{self// E0277 here now}}
I wish I knew how to say in Rust that a (Self or generic) type is either Sizedor a trait object, thus will work with the new trait upcasting -- it would make the feature significantly more usable for me.
Anyway, this is moving it away from a bug report into a more general discussion, which is not appropriate, so I will close it there.
I tried this code (brief version):
I expected this code to compile with Rust 1.86, given the new upcasting support.
Instead, the compiler gives E0277.
Why should this code now work? Self must be either:
In either case, it should now be possible to cast to a Foo trait object, but the compiler is not allowing it yet. It's
like some part of the upcasting support is missing.
The problem occurs with stable 1.86. As of time of writing, the problem still occurs with nightly (1.88).
Another, more verbose, example, showing the same issue in a generic context, with explanatory comments:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e2e4ee0e645105cbff33fa49d317a8d
The text was updated successfully, but these errors were encountered: