Skip to content

Commit bd0d533

Browse files
committed
fix structurally relate for weak aliases
1 parent 8ebb3d4 commit bd0d533

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,8 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
544544
Ok(tcx.mk_fn_ptr(fty))
545545
}
546546

547-
// these two are already handled downstream in case of lazy normalization
548-
(&ty::Alias(ty::Projection, a_data), &ty::Alias(ty::Projection, b_data)) => {
549-
let projection_ty = relation.relate(a_data, b_data)?;
550-
Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs))
551-
}
552-
553-
(&ty::Alias(ty::Inherent, a_data), &ty::Alias(ty::Inherent, b_data)) => {
554-
let alias_ty = relation.relate(a_data, b_data)?;
555-
Ok(tcx.mk_alias(ty::Inherent, tcx.mk_alias_ty(alias_ty.def_id, alias_ty.substs)))
556-
}
557-
547+
// The substs of opaque types may not all be invariant, so we have
548+
// to treat them separately from other aliases.
558549
(
559550
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
560551
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
@@ -571,6 +562,19 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
571562
Ok(tcx.mk_opaque(a_def_id, substs))
572563
}
573564

565+
// Alias tend to mostly already be handled downstream due to normalization.
566+
(&ty::Alias(a_kind, a_data), &ty::Alias(b_kind, b_data)) => {
567+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): This if can be removed
568+
// and the assert uncommented once the new desugaring is stable.
569+
if a_kind == b_kind {
570+
let alias_ty = relation.relate(a_data, b_data)?;
571+
// assert_eq!(a_kind, b_kind);
572+
Ok(tcx.mk_alias(a_kind, alias_ty))
573+
} else {
574+
Err(TypeError::Sorts(expected_found(relation, a, b)))
575+
}
576+
}
577+
574578
_ => Err(TypeError::Sorts(expected_found(relation, a, b))),
575579
}
576580
}

0 commit comments

Comments
 (0)