@@ -544,17 +544,8 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
544
544
Ok ( tcx. mk_fn_ptr ( fty) )
545
545
}
546
546
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.
558
549
(
559
550
& ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : a_def_id, substs : a_substs, .. } ) ,
560
551
& 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>>(
571
562
Ok ( tcx. mk_opaque ( a_def_id, substs) )
572
563
}
573
564
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
+
574
578
_ => Err ( TypeError :: Sorts ( expected_found ( relation, a, b) ) ) ,
575
579
}
576
580
}
0 commit comments