@@ -1235,6 +1235,7 @@ pub struct TyParam {
1235
1235
pub did : DefId ,
1236
1236
pub bounds : Vec < TyParamBound > ,
1237
1237
pub default : Option < Type > ,
1238
+ pub synthetic : Option < hir:: SyntheticTyParamKind > ,
1238
1239
}
1239
1240
1240
1241
impl Clean < TyParam > for hir:: TyParam {
@@ -1244,6 +1245,7 @@ impl Clean<TyParam> for hir::TyParam {
1244
1245
did : cx. tcx . hir . local_def_id ( self . id ) ,
1245
1246
bounds : self . bounds . clean ( cx) ,
1246
1247
default : self . default . clean ( cx) ,
1248
+ synthetic : self . synthetic ,
1247
1249
}
1248
1250
}
1249
1251
}
@@ -1259,7 +1261,8 @@ impl<'tcx> Clean<TyParam> for ty::TypeParameterDef {
1259
1261
Some ( cx. tcx . type_of ( self . def_id ) . clean ( cx) )
1260
1262
} else {
1261
1263
None
1262
- }
1264
+ } ,
1265
+ synthetic : None ,
1263
1266
}
1264
1267
}
1265
1268
}
@@ -1627,6 +1630,16 @@ pub enum GenericParam {
1627
1630
Type ( TyParam ) ,
1628
1631
}
1629
1632
1633
+ impl GenericParam {
1634
+ pub fn is_synthetic_type_param ( & self ) -> bool {
1635
+ if let GenericParam :: Type ( ref t) = * self {
1636
+ t. synthetic . is_some ( )
1637
+ } else {
1638
+ false
1639
+ }
1640
+ }
1641
+ }
1642
+
1630
1643
impl Clean < GenericParam > for hir:: GenericParam {
1631
1644
fn clean ( & self , cx : & DocContext ) -> GenericParam {
1632
1645
match * self {
@@ -1759,11 +1772,12 @@ pub struct Method {
1759
1772
1760
1773
impl < ' a > Clean < Method > for ( & ' a hir:: MethodSig , & ' a hir:: Generics , hir:: BodyId ) {
1761
1774
fn clean ( & self , cx : & DocContext ) -> Method {
1775
+ let generics = self . 1 . clean ( cx) ;
1762
1776
Method {
1763
- generics : self . 1 . clean ( cx) ,
1777
+ decl : enter_impl_trait ( cx, & generics. params , || ( & * self . 0 . decl , self . 2 ) . clean ( cx) ) ,
1778
+ generics,
1764
1779
unsafety : self . 0 . unsafety ,
1765
1780
constness : self . 0 . constness ,
1766
- decl : ( & * self . 0 . decl , self . 2 ) . clean ( cx) ,
1767
1781
abi : self . 0 . abi
1768
1782
}
1769
1783
}
@@ -1788,6 +1802,8 @@ pub struct Function {
1788
1802
1789
1803
impl Clean < Item > for doctree:: Function {
1790
1804
fn clean ( & self , cx : & DocContext ) -> Item {
1805
+ let generics = self . generics . clean ( cx) ;
1806
+ let decl = enter_impl_trait ( cx, & generics. params , || ( & self . decl , self . body ) . clean ( cx) ) ;
1791
1807
Item {
1792
1808
name : Some ( self . name . clean ( cx) ) ,
1793
1809
attrs : self . attrs . clean ( cx) ,
@@ -1797,8 +1813,8 @@ impl Clean<Item> for doctree::Function {
1797
1813
deprecation : self . depr . clean ( cx) ,
1798
1814
def_id : cx. tcx . hir . local_def_id ( self . id ) ,
1799
1815
inner : FunctionItem ( Function {
1800
- decl : ( & self . decl , self . body ) . clean ( cx ) ,
1801
- generics : self . generics . clean ( cx ) ,
1816
+ decl,
1817
+ generics,
1802
1818
unsafety : self . unsafety ,
1803
1819
constness : self . constness ,
1804
1820
abi : self . abi ,
@@ -1883,7 +1899,8 @@ impl<'a, 'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
1883
1899
vec ! [ ] . into_iter ( )
1884
1900
} else {
1885
1901
cx. tcx . fn_arg_names ( did) . into_iter ( )
1886
- } . peekable ( ) ;
1902
+ } ;
1903
+
1887
1904
FnDecl {
1888
1905
output : Return ( sig. skip_binder ( ) . output ( ) . clean ( cx) ) ,
1889
1906
attrs : Attributes :: default ( ) ,
@@ -2025,10 +2042,13 @@ impl Clean<Item> for hir::TraitItem {
2025
2042
MethodItem ( ( sig, & self . generics , body) . clean ( cx) )
2026
2043
}
2027
2044
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Required ( ref names) ) => {
2045
+ let generics = self . generics . clean ( cx) ;
2028
2046
TyMethodItem ( TyMethod {
2029
2047
unsafety : sig. unsafety . clone ( ) ,
2030
- decl : ( & * sig. decl , & names[ ..] ) . clean ( cx) ,
2031
- generics : self . generics . clean ( cx) ,
2048
+ decl : enter_impl_trait ( cx, & generics. params , || {
2049
+ ( & * sig. decl , & names[ ..] ) . clean ( cx)
2050
+ } ) ,
2051
+ generics,
2032
2052
abi : sig. abi
2033
2053
} )
2034
2054
}
@@ -2532,6 +2552,12 @@ impl Clean<Type> for hir::Ty {
2532
2552
return new_ty;
2533
2553
}
2534
2554
2555
+ if let Def :: TyParam ( did) = path. def {
2556
+ if let Some ( bounds) = cx. impl_trait_bounds . borrow_mut ( ) . remove ( & did) {
2557
+ return ImplTrait ( bounds) ;
2558
+ }
2559
+ }
2560
+
2535
2561
let mut alias = None ;
2536
2562
if let Def :: TyAlias ( def_id) = path. def {
2537
2563
// Substitute private type aliases
@@ -3244,10 +3270,13 @@ pub struct BareFunctionDecl {
3244
3270
3245
3271
impl Clean < BareFunctionDecl > for hir:: BareFnTy {
3246
3272
fn clean ( & self , cx : & DocContext ) -> BareFunctionDecl {
3273
+ let generic_params = self . generic_params . clean ( cx) ;
3247
3274
BareFunctionDecl {
3248
3275
unsafety : self . unsafety ,
3249
- generic_params : self . generic_params . clean ( cx) ,
3250
- decl : ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx) ,
3276
+ decl : enter_impl_trait ( cx, & generic_params, || {
3277
+ ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx)
3278
+ } ) ,
3279
+ generic_params,
3251
3280
abi : self . abi ,
3252
3281
}
3253
3282
}
@@ -3548,9 +3577,12 @@ impl Clean<Item> for hir::ForeignItem {
3548
3577
fn clean ( & self , cx : & DocContext ) -> Item {
3549
3578
let inner = match self . node {
3550
3579
hir:: ForeignItemFn ( ref decl, ref names, ref generics) => {
3580
+ let generics = generics. clean ( cx) ;
3551
3581
ForeignFunctionItem ( Function {
3552
- decl : ( & * * decl, & names[ ..] ) . clean ( cx) ,
3553
- generics : generics. clean ( cx) ,
3582
+ decl : enter_impl_trait ( cx, & generics. params , || {
3583
+ ( & * * decl, & names[ ..] ) . clean ( cx)
3584
+ } ) ,
3585
+ generics,
3554
3586
unsafety : hir:: Unsafety :: Unsafe ,
3555
3587
abi : Abi :: Rust ,
3556
3588
constness : hir:: Constness :: NotConst ,
@@ -3852,6 +3884,29 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
3852
3884
once ( crate_name) . chain ( relative) . collect ( )
3853
3885
}
3854
3886
3887
+ pub fn enter_impl_trait < F , R > ( cx : & DocContext , gps : & [ GenericParam ] , f : F ) -> R
3888
+ where
3889
+ F : FnOnce ( ) -> R ,
3890
+ {
3891
+ let bounds = gps. iter ( )
3892
+ . filter_map ( |p| {
3893
+ if let GenericParam :: Type ( ref tp) = * p {
3894
+ if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
3895
+ return Some ( ( tp. did , tp. bounds . clone ( ) ) ) ;
3896
+ }
3897
+ }
3898
+
3899
+ None
3900
+ } )
3901
+ . collect :: < FxHashMap < DefId , Vec < TyParamBound > > > ( ) ;
3902
+
3903
+ let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , bounds) ;
3904
+ let r = f ( ) ;
3905
+ assert ! ( cx. impl_trait_bounds. borrow( ) . is_empty( ) ) ;
3906
+ * cx. impl_trait_bounds . borrow_mut ( ) = old_bounds;
3907
+ r
3908
+ }
3909
+
3855
3910
// Start of code copied from rust-clippy
3856
3911
3857
3912
pub fn get_trait_def_id ( tcx : & TyCtxt , path : & [ & str ] , use_local : bool ) -> Option < DefId > {
0 commit comments