@@ -1720,11 +1720,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1720
1720
ty:: GenericParamDefKind :: Const { .. } => None ,
1721
1721
} ) . collect :: < Vec < GenericParamDef > > ( ) ;
1722
1722
1723
- // (param index, def id of trait) -> (name, type)
1724
- let mut impl_trait_proj = FxHashMap :: < ( u32 , DefId ) , Vec < ( String , Type ) > > :: default ( ) ;
1723
+ // param index -> [(DefId of trait, associated type name, type)]
1724
+ let mut impl_trait_proj =
1725
+ FxHashMap :: < u32 , Vec < ( DefId , String , Ty < ' tcx > ) > > :: default ( ) ;
1725
1726
1726
1727
let mut where_predicates = preds. predicates . iter ( )
1727
1728
. flat_map ( |( p, _) | {
1729
+ let mut projection = None ;
1728
1730
let param_idx = ( || {
1729
1731
if let Some ( trait_ref) = p. to_opt_poly_trait_ref ( ) {
1730
1732
if let ty:: Param ( param) = trait_ref. self_ty ( ) . sty {
@@ -1734,8 +1736,9 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1734
1736
if let ty:: Param ( param) = outlives. skip_binder ( ) . 0 . sty {
1735
1737
return Some ( param. index ) ;
1736
1738
}
1737
- } else if let ty:: Predicate :: Projection ( proj) = p {
1738
- if let ty:: Param ( param) = proj. skip_binder ( ) . projection_ty . self_ty ( ) . sty {
1739
+ } else if let ty:: Predicate :: Projection ( p) = p {
1740
+ if let ty:: Param ( param) = p. skip_binder ( ) . projection_ty . self_ty ( ) . sty {
1741
+ projection = Some ( p) ;
1739
1742
return Some ( param. index ) ;
1740
1743
}
1741
1744
}
@@ -1755,16 +1758,15 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1755
1758
. filter ( |b| !b. is_sized_bound ( cx) )
1756
1759
) ;
1757
1760
1758
- let proj = match & p {
1759
- WherePredicate :: EqPredicate { lhs, rhs } => Some ( ( lhs, rhs) )
1760
- . and_then ( |( lhs, rhs) | Some ( ( lhs. projection ( ) ?, rhs) ) ) ,
1761
- _ => None ,
1762
- } ;
1763
- if let Some ( ( ( _, trait_did, name) , rhs) ) = proj {
1761
+ let proj = projection
1762
+ . map ( |p| ( p. skip_binder ( ) . projection_ty . clean ( cx) , p. skip_binder ( ) . ty ) ) ;
1763
+ if let Some ( ( ( _, trait_did, name) , rhs) ) =
1764
+ proj. as_ref ( ) . and_then ( |( lhs, rhs) | Some ( ( lhs. projection ( ) ?, rhs) ) )
1765
+ {
1764
1766
impl_trait_proj
1765
- . entry ( ( param_idx, trait_did ) )
1767
+ . entry ( param_idx)
1766
1768
. or_default ( )
1767
- . push ( ( name. to_string ( ) , rhs. clone ( ) ) ) ;
1769
+ . push ( ( trait_did , name. to_string ( ) , rhs) ) ;
1768
1770
}
1769
1771
1770
1772
return None ;
@@ -1775,18 +1777,6 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1775
1777
} )
1776
1778
. collect :: < Vec < _ > > ( ) ;
1777
1779
1778
- for ( ( param_idx, trait_did) , bounds) in impl_trait_proj {
1779
- for ( name, rhs) in bounds {
1780
- simplify:: merge_bounds (
1781
- cx,
1782
- impl_trait. get_mut ( & param_idx. into ( ) ) . unwrap ( ) ,
1783
- trait_did,
1784
- & name,
1785
- & rhs,
1786
- ) ;
1787
- }
1788
- }
1789
-
1790
1780
// Move `TraitPredicate`s to the front.
1791
1781
for ( _, bounds) in impl_trait. iter_mut ( ) {
1792
1782
bounds. sort_by_key ( |b| if let GenericBound :: TraitBound ( ..) = b {
@@ -1796,7 +1786,25 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1796
1786
} ) ;
1797
1787
}
1798
1788
1799
- cx. impl_trait_bounds . borrow_mut ( ) . extend ( impl_trait) ;
1789
+ for ( param, mut bounds) in impl_trait {
1790
+ if let crate :: core:: ImplTraitParam :: ParamIndex ( idx) = param {
1791
+ if let Some ( proj) = impl_trait_proj. remove ( & idx) {
1792
+ for ( trait_did, name, rhs) in proj {
1793
+ simplify:: merge_bounds (
1794
+ cx,
1795
+ & mut bounds,
1796
+ trait_did,
1797
+ & name,
1798
+ & rhs. clean ( cx) ,
1799
+ ) ;
1800
+ }
1801
+ }
1802
+ } else {
1803
+ unreachable ! ( ) ;
1804
+ }
1805
+
1806
+ cx. impl_trait_bounds . borrow_mut ( ) . insert ( param, bounds) ;
1807
+ }
1800
1808
1801
1809
// Type parameters and have a Sized bound by default unless removed with
1802
1810
// ?Sized. Scan through the predicates and mark any type parameter with
0 commit comments