@@ -1605,6 +1605,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1605
1605
on_ambiguity : impl FnOnce ( ) ,
1606
1606
) -> ControlFlow < T , ( ) > {
1607
1607
let mut idx = 0 ;
1608
+ let mut in_parent_alias_type = false ;
1609
+
1608
1610
loop {
1609
1611
let ( kind, alias_ty) = match * self_ty. kind ( ) {
1610
1612
ty:: Alias ( kind @ ( ty:: Projection | ty:: Opaque ) , alias_ty) => ( kind, alias_ty) ,
@@ -1618,6 +1620,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1618
1620
for bound in
1619
1621
self . tcx ( ) . item_bounds ( alias_ty. def_id ) . instantiate ( self . tcx ( ) , alias_ty. args )
1620
1622
{
1623
+ // HACK: On subsequent recursions, we only care about bounds that don't
1624
+ // share the same type as `self_ty`. This is because for truly rigid
1625
+ // projections, we will never be able to equate, e.g. `<T as Tr>::A`
1626
+ // with `<<T as Tr>::A as Tr>::A`.
1627
+ if in_parent_alias_type {
1628
+ match bound. kind ( ) . skip_binder ( ) {
1629
+ ty:: ClauseKind :: Trait ( tr) if tr. self_ty ( ) == self_ty => continue ,
1630
+ ty:: ClauseKind :: Projection ( p) if p. self_ty ( ) == self_ty => continue ,
1631
+ _ => { }
1632
+ }
1633
+ }
1634
+
1621
1635
for_each ( self , bound, idx) ?;
1622
1636
idx += 1 ;
1623
1637
}
@@ -1627,6 +1641,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1627
1641
} else {
1628
1642
return ControlFlow :: Continue ( ( ) ) ;
1629
1643
}
1644
+
1645
+ in_parent_alias_type = true ;
1630
1646
}
1631
1647
}
1632
1648
0 commit comments