Skip to content

Commit 4f978db

Browse files
Unbreak upcasting
1 parent 6e6c49e commit 4f978db

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
779779

780780
match (source.kind(), target.kind()) {
781781
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
782-
(&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => {
782+
(&ty::Dynamic(ref data_a, _, dyn_a), &ty::Dynamic(ref data_b, _, dyn_b))
783+
if dyn_a == dyn_b =>
784+
{
783785
// Upcast coercions permit several things:
784786
//
785787
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
919919
let mut nested = vec![];
920920
match (source.kind(), target.kind()) {
921921
// Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping).
922-
(&ty::Dynamic(ref data_a, r_a, ty::Dyn), &ty::Dynamic(ref data_b, r_b, ty::Dyn)) => {
922+
(&ty::Dynamic(ref data_a, r_a, dyn_a), &ty::Dynamic(ref data_b, r_b, dyn_b))
923+
if dyn_a == dyn_b =>
924+
{
923925
// See `assemble_candidates_for_unsizing` for more info.
924926
// We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`.
925927
let iter = data_a
@@ -938,7 +940,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
938940
.map(ty::Binder::dummy),
939941
);
940942
let existential_predicates = tcx.mk_poly_existential_predicates(iter);
941-
let source_trait = tcx.mk_dynamic(existential_predicates, r_b, ty::Dyn);
943+
let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a);
942944

943945
// Require that the traits involved in this upcast are **equal**;
944946
// only the **lifetime bound** is changed.

0 commit comments

Comments
 (0)