@@ -1235,6 +1235,7 @@ pub struct TyParam {
12351235 pub did : DefId ,
12361236 pub bounds : Vec < TyParamBound > ,
12371237 pub default : Option < Type > ,
1238+ pub synthetic : Option < hir:: SyntheticTyParamKind > ,
12381239}
12391240
12401241impl Clean < TyParam > for hir:: TyParam {
@@ -1244,6 +1245,7 @@ impl Clean<TyParam> for hir::TyParam {
12441245 did : cx. tcx . hir . local_def_id ( self . id ) ,
12451246 bounds : self . bounds . clean ( cx) ,
12461247 default : self . default . clean ( cx) ,
1248+ synthetic : self . synthetic ,
12471249 }
12481250 }
12491251}
@@ -1259,7 +1261,8 @@ impl<'tcx> Clean<TyParam> for ty::TypeParameterDef {
12591261 Some ( cx. tcx . type_of ( self . def_id ) . clean ( cx) )
12601262 } else {
12611263 None
1262- }
1264+ } ,
1265+ synthetic : None ,
12631266 }
12641267 }
12651268}
@@ -1627,6 +1630,16 @@ pub enum GenericParam {
16271630 Type ( TyParam ) ,
16281631}
16291632
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+
16301643impl Clean < GenericParam > for hir:: GenericParam {
16311644 fn clean ( & self , cx : & DocContext ) -> GenericParam {
16321645 match * self {
@@ -1759,11 +1772,12 @@ pub struct Method {
17591772
17601773impl < ' a > Clean < Method > for ( & ' a hir:: MethodSig , & ' a hir:: Generics , hir:: BodyId ) {
17611774 fn clean ( & self , cx : & DocContext ) -> Method {
1775+ let generics = self . 1 . clean ( cx) ;
17621776 Method {
1763- generics : self . 1 . clean ( cx) ,
1777+ decl : enter_impl_trait ( cx, & generics. params , || ( & * self . 0 . decl , self . 2 ) . clean ( cx) ) ,
1778+ generics,
17641779 unsafety : self . 0 . unsafety ,
17651780 constness : self . 0 . constness ,
1766- decl : ( & * self . 0 . decl , self . 2 ) . clean ( cx) ,
17671781 abi : self . 0 . abi
17681782 }
17691783 }
@@ -1788,6 +1802,8 @@ pub struct Function {
17881802
17891803impl Clean < Item > for doctree:: Function {
17901804 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) ) ;
17911807 Item {
17921808 name : Some ( self . name . clean ( cx) ) ,
17931809 attrs : self . attrs . clean ( cx) ,
@@ -1797,8 +1813,8 @@ impl Clean<Item> for doctree::Function {
17971813 deprecation : self . depr . clean ( cx) ,
17981814 def_id : cx. tcx . hir . local_def_id ( self . id ) ,
17991815 inner : FunctionItem ( Function {
1800- decl : ( & self . decl , self . body ) . clean ( cx ) ,
1801- generics : self . generics . clean ( cx ) ,
1816+ decl,
1817+ generics,
18021818 unsafety : self . unsafety ,
18031819 constness : self . constness ,
18041820 abi : self . abi ,
@@ -1883,7 +1899,8 @@ impl<'a, 'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
18831899 vec ! [ ] . into_iter ( )
18841900 } else {
18851901 cx. tcx . fn_arg_names ( did) . into_iter ( )
1886- } . peekable ( ) ;
1902+ } ;
1903+
18871904 FnDecl {
18881905 output : Return ( sig. skip_binder ( ) . output ( ) . clean ( cx) ) ,
18891906 attrs : Attributes :: default ( ) ,
@@ -2025,10 +2042,13 @@ impl Clean<Item> for hir::TraitItem {
20252042 MethodItem ( ( sig, & self . generics , body) . clean ( cx) )
20262043 }
20272044 hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Required ( ref names) ) => {
2045+ let generics = self . generics . clean ( cx) ;
20282046 TyMethodItem ( TyMethod {
20292047 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,
20322052 abi : sig. abi
20332053 } )
20342054 }
@@ -2532,6 +2552,12 @@ impl Clean<Type> for hir::Ty {
25322552 return new_ty;
25332553 }
25342554
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+
25352561 let mut alias = None ;
25362562 if let Def :: TyAlias ( def_id) = path. def {
25372563 // Substitute private type aliases
@@ -3244,10 +3270,13 @@ pub struct BareFunctionDecl {
32443270
32453271impl Clean < BareFunctionDecl > for hir:: BareFnTy {
32463272 fn clean ( & self , cx : & DocContext ) -> BareFunctionDecl {
3273+ let generic_params = self . generic_params . clean ( cx) ;
32473274 BareFunctionDecl {
32483275 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,
32513280 abi : self . abi ,
32523281 }
32533282 }
@@ -3548,9 +3577,12 @@ impl Clean<Item> for hir::ForeignItem {
35483577 fn clean ( & self , cx : & DocContext ) -> Item {
35493578 let inner = match self . node {
35503579 hir:: ForeignItemFn ( ref decl, ref names, ref generics) => {
3580+ let generics = generics. clean ( cx) ;
35513581 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,
35543586 unsafety : hir:: Unsafety :: Unsafe ,
35553587 abi : Abi :: Rust ,
35563588 constness : hir:: Constness :: NotConst ,
@@ -3852,6 +3884,29 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
38523884 once ( crate_name) . chain ( relative) . collect ( )
38533885}
38543886
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+
38553910// Start of code copied from rust-clippy
38563911
38573912pub fn get_trait_def_id ( tcx : & TyCtxt , path : & [ & str ] , use_local : bool ) -> Option < DefId > {
0 commit comments