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
As @nikomatsakis said on Zulip, this is sort of a special case of upcasting. In general, if trait A is a subtype of trait B (i.e. A's bounds include all of B's bounds and possibly more), then dyn A should be convertible to dyn B.
Activity
alexreg commentedon Nov 2, 2018
Here's an example from my comment in #55101:
yields
Whereas references to A and B should clearly be interchangeable.
alexreg commentedon Nov 2, 2018
As @nikomatsakis said on Zulip, this is sort of a special case of upcasting. In general, if trait
Ais a subtype of traitB(i.e. A's bounds include all of B's bounds and possibly more), thendyn Ashould be convertible todyn B.alexreg commentedon Dec 5, 2018
Note a seemingly surprising consequence on coherence that this has:
Playground
This is correct behaviour for now, and it doesn't cause any ICEs, but obviously is not what one would expect intuitively.
maltuned commentedon Apr 4, 2026
Has this issue been fixed now?
The above code passes compilation on
rustc 1.95.0-nightly (efc9e1b50 2026-02-06).fmease commentedon Oct 22, 2026
Yep, nowadays we expand trait aliases "away" "eagerly" inside trait object types. Whether that behavior will stay is a separate question.