Cannot upcast dyn Trait
in a way that reduces the number of associated types
#114035
Labels
C-bug
Category: This is a bug.
F-trait_upcasting
`#![feature(trait_upcasting)]`
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I tried this code:
I expected to see it compile.
Instead, this happened:
The algorithm we use to do trait upcasting is incorrect, since it simply copies the existential associated types over:
rust/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Lines 933 to 937 in fd56162
So if we upcast to a trait with fewer associated types (like
B
), then the subtyping we do here is wrong:rust/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Lines 949 to 953 in fd56162
Since we require the list of existential trait bounds to be structurally compatible:
rust/compiler/rustc_middle/src/ty/relate.rs
Lines 689 to 698 in fd56162
The text was updated successfully, but these errors were encountered: