@@ -47,7 +47,7 @@ use std::u32;
47
47
48
48
use parking_lot:: ReentrantMutex ;
49
49
50
- use crate :: core:: { self , DocContext } ;
50
+ use crate :: core:: { self , DocContext , ImplTraitParam } ;
51
51
use crate :: doctree;
52
52
use crate :: visit_ast;
53
53
use crate :: html:: render:: { cache, ExternalLocation } ;
@@ -1536,7 +1536,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
1536
1536
ty:: GenericParamDefKind :: Lifetime => {
1537
1537
( self . name . to_string ( ) , GenericParamDefKind :: Lifetime )
1538
1538
}
1539
- ty:: GenericParamDefKind :: Type { has_default, .. } => {
1539
+ ty:: GenericParamDefKind :: Type { has_default, synthetic , .. } => {
1540
1540
cx. renderinfo . borrow_mut ( ) . external_param_names
1541
1541
. insert ( self . def_id , self . name . clean ( cx) ) ;
1542
1542
let default = if has_default {
@@ -1548,7 +1548,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
1548
1548
did : self . def_id ,
1549
1549
bounds : vec ! [ ] , // These are filled in from the where-clauses.
1550
1550
default,
1551
- synthetic : None ,
1551
+ synthetic,
1552
1552
} )
1553
1553
}
1554
1554
ty:: GenericParamDefKind :: Const { .. } => {
@@ -1637,7 +1637,7 @@ impl Clean<Generics> for hir::Generics {
1637
1637
match param. kind {
1638
1638
GenericParamDefKind :: Lifetime => unreachable ! ( ) ,
1639
1639
GenericParamDefKind :: Type { did, ref bounds, .. } => {
1640
- cx. impl_trait_bounds . borrow_mut ( ) . insert ( did, bounds. clone ( ) ) ;
1640
+ cx. impl_trait_bounds . borrow_mut ( ) . insert ( did. into ( ) , bounds. clone ( ) ) ;
1641
1641
}
1642
1642
GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
1643
1643
}
@@ -1692,25 +1692,76 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1692
1692
1693
1693
let ( gens, preds) = * self ;
1694
1694
1695
+ // Don't populate `cx.impl_trait_bounds` before `clean`ning `where` clauses,
1696
+ // since `Clean for ty::Predicate` would consume them.
1697
+ let mut impl_trait = FxHashMap :: < ImplTraitParam , Vec < _ > > :: default ( ) ;
1698
+
1695
1699
// Bounds in the type_params and lifetimes fields are repeated in the
1696
1700
// predicates field (see rustc_typeck::collect::ty_generics), so remove
1697
1701
// them.
1698
- let stripped_typarams = gens. params . iter ( ) . filter_map ( |param| match param. kind {
1699
- ty:: GenericParamDefKind :: Lifetime => None ,
1700
- ty:: GenericParamDefKind :: Type { .. } => {
1701
- if param. name . as_symbol ( ) == kw:: SelfUpper {
1702
- assert_eq ! ( param. index, 0 ) ;
1703
- return None ;
1702
+ let stripped_typarams = gens. params . iter ( ) . enumerate ( )
1703
+ . filter_map ( |( i, param) | match param. kind {
1704
+ ty:: GenericParamDefKind :: Lifetime => None ,
1705
+ ty:: GenericParamDefKind :: Type { synthetic, .. } => {
1706
+ if param. name . as_symbol ( ) == kw:: SelfUpper {
1707
+ assert_eq ! ( param. index, 0 ) ;
1708
+ return None ;
1709
+ }
1710
+ if synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
1711
+ impl_trait. insert ( ( i as u32 ) . into ( ) , vec ! [ ] ) ;
1712
+ return None ;
1713
+ }
1714
+ Some ( param. clean ( cx) )
1704
1715
}
1705
- Some ( param. clean ( cx) )
1706
- }
1707
- ty:: GenericParamDefKind :: Const { .. } => None ,
1708
- } ) . collect :: < Vec < GenericParamDef > > ( ) ;
1716
+ ty:: GenericParamDefKind :: Const { .. } => None ,
1717
+ } ) . collect :: < Vec < GenericParamDef > > ( ) ;
1709
1718
1710
1719
let mut where_predicates = preds. predicates . iter ( )
1711
- . flat_map ( |( p, _) | p. clean ( cx) )
1720
+ . flat_map ( |( p, _) | {
1721
+ let param_idx = if let Some ( trait_ref) = p. to_opt_poly_trait_ref ( ) {
1722
+ if let ty:: Param ( param) = trait_ref. self_ty ( ) . sty {
1723
+ Some ( param. index )
1724
+ } else {
1725
+ None
1726
+ }
1727
+ } else if let Some ( outlives) = p. to_opt_type_outlives ( ) {
1728
+ if let ty:: Param ( param) = outlives. skip_binder ( ) . 0 . sty {
1729
+ Some ( param. index )
1730
+ } else {
1731
+ None
1732
+ }
1733
+ } else {
1734
+ None
1735
+ } ;
1736
+
1737
+ let p = p. clean ( cx) ?;
1738
+
1739
+ if let Some ( b) = param_idx. and_then ( |i| impl_trait. get_mut ( & i. into ( ) ) ) {
1740
+ b. extend (
1741
+ p. get_bounds ( )
1742
+ . into_iter ( )
1743
+ . flatten ( )
1744
+ . cloned ( )
1745
+ . filter ( |b| !b. is_sized_bound ( cx) )
1746
+ ) ;
1747
+ return None ;
1748
+ }
1749
+
1750
+ Some ( p)
1751
+ } )
1712
1752
. collect :: < Vec < _ > > ( ) ;
1713
1753
1754
+ // Move `TraitPredicate`s to the front.
1755
+ for ( _, bounds) in impl_trait. iter_mut ( ) {
1756
+ bounds. sort_by_key ( |b| if let GenericBound :: TraitBound ( ..) = b {
1757
+ false
1758
+ } else {
1759
+ true
1760
+ } ) ;
1761
+ }
1762
+
1763
+ cx. impl_trait_bounds . borrow_mut ( ) . extend ( impl_trait) ;
1764
+
1714
1765
// Type parameters and have a Sized bound by default unless removed with
1715
1766
// ?Sized. Scan through the predicates and mark any type parameter with
1716
1767
// a Sized bound, removing the bounds as we find them.
@@ -2789,7 +2840,7 @@ impl Clean<Type> for hir::Ty {
2789
2840
if let Some ( new_ty) = cx. ty_substs . borrow ( ) . get ( & did) . cloned ( ) {
2790
2841
return new_ty;
2791
2842
}
2792
- if let Some ( bounds) = cx. impl_trait_bounds . borrow_mut ( ) . remove ( & did) {
2843
+ if let Some ( bounds) = cx. impl_trait_bounds . borrow_mut ( ) . remove ( & did. into ( ) ) {
2793
2844
return ImplTrait ( bounds) ;
2794
2845
}
2795
2846
}
@@ -3079,7 +3130,13 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
3079
3130
3080
3131
ty:: Projection ( ref data) => data. clean ( cx) ,
3081
3132
3082
- ty:: Param ( ref p) => Generic ( p. name . to_string ( ) ) ,
3133
+ ty:: Param ( ref p) => {
3134
+ if let Some ( bounds) = cx. impl_trait_bounds . borrow_mut ( ) . remove ( & p. index . into ( ) ) {
3135
+ ImplTrait ( bounds)
3136
+ } else {
3137
+ Generic ( p. name . to_string ( ) )
3138
+ }
3139
+ }
3083
3140
3084
3141
ty:: Opaque ( def_id, substs) => {
3085
3142
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
0 commit comments