@@ -1774,11 +1774,12 @@ pub struct Method {
1774
1774
1775
1775
impl < ' a > Clean < Method > for ( & ' a hir:: MethodSig , & ' a hir:: Generics , hir:: BodyId ) {
1776
1776
fn clean ( & self , cx : & DocContext ) -> Method {
1777
+ let generics = self . 1 . clean ( cx) ;
1777
1778
Method {
1778
- generics : self . 1 . clean ( cx) ,
1779
+ decl : enter_impl_trait ( cx, & generics. params , || ( & * self . 0 . decl , self . 2 ) . clean ( cx) ) ,
1780
+ generics,
1779
1781
unsafety : self . 0 . unsafety ,
1780
1782
constness : self . 0 . constness ,
1781
- decl : ( & * self . 0 . decl , self . 2 ) . clean ( cx) ,
1782
1783
abi : self . 0 . abi
1783
1784
}
1784
1785
}
@@ -1803,6 +1804,8 @@ pub struct Function {
1803
1804
1804
1805
impl Clean < Item > for doctree:: Function {
1805
1806
fn clean ( & self , cx : & DocContext ) -> Item {
1807
+ let generics = self . generics . clean ( cx) ;
1808
+ let decl = enter_impl_trait ( cx, & generics. params , || ( & self . decl , self . body ) . clean ( cx) ) ;
1806
1809
Item {
1807
1810
name : Some ( self . name . clean ( cx) ) ,
1808
1811
attrs : self . attrs . clean ( cx) ,
@@ -1812,8 +1815,8 @@ impl Clean<Item> for doctree::Function {
1812
1815
deprecation : self . depr . clean ( cx) ,
1813
1816
def_id : cx. tcx . hir . local_def_id ( self . id ) ,
1814
1817
inner : FunctionItem ( Function {
1815
- decl : ( & self . decl , self . body ) . clean ( cx ) ,
1816
- generics : self . generics . clean ( cx ) ,
1818
+ decl,
1819
+ generics,
1817
1820
unsafety : self . unsafety ,
1818
1821
constness : self . constness ,
1819
1822
abi : self . abi ,
@@ -2040,10 +2043,13 @@ impl Clean<Item> for hir::TraitItem {
2040
2043
MethodItem ( ( sig, & self . generics , body) . clean ( cx) )
2041
2044
}
2042
2045
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Required ( ref names) ) => {
2046
+ let generics = self . generics . clean ( cx) ;
2043
2047
TyMethodItem ( TyMethod {
2044
2048
unsafety : sig. unsafety . clone ( ) ,
2045
- decl : ( & * sig. decl , & names[ ..] ) . clean ( cx) ,
2046
- generics : self . generics . clean ( cx) ,
2049
+ decl : enter_impl_trait ( cx, & generics. params , || {
2050
+ ( & * sig. decl , & names[ ..] ) . clean ( cx)
2051
+ } ) ,
2052
+ generics,
2047
2053
abi : sig. abi
2048
2054
} )
2049
2055
}
@@ -2547,6 +2553,12 @@ impl Clean<Type> for hir::Ty {
2547
2553
return new_ty;
2548
2554
}
2549
2555
2556
+ if let Def :: TyParam ( did) = path. def {
2557
+ if let Some ( bounds) = cx. impl_trait_bounds . borrow_mut ( ) . remove ( & did) {
2558
+ return ImplTrait ( bounds) ;
2559
+ }
2560
+ }
2561
+
2550
2562
let mut alias = None ;
2551
2563
if let Def :: TyAlias ( def_id) = path. def {
2552
2564
// Substitute private type aliases
@@ -3259,10 +3271,13 @@ pub struct BareFunctionDecl {
3259
3271
3260
3272
impl Clean < BareFunctionDecl > for hir:: BareFnTy {
3261
3273
fn clean ( & self , cx : & DocContext ) -> BareFunctionDecl {
3274
+ let generic_params = self . generic_params . clean ( cx) ;
3262
3275
BareFunctionDecl {
3263
3276
unsafety : self . unsafety ,
3264
- generic_params : self . generic_params . clean ( cx) ,
3265
- decl : ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx) ,
3277
+ decl : enter_impl_trait ( cx, & generic_params, || {
3278
+ ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx)
3279
+ } ) ,
3280
+ generic_params,
3266
3281
abi : self . abi ,
3267
3282
}
3268
3283
}
@@ -3563,9 +3578,12 @@ impl Clean<Item> for hir::ForeignItem {
3563
3578
fn clean ( & self , cx : & DocContext ) -> Item {
3564
3579
let inner = match self . node {
3565
3580
hir:: ForeignItemFn ( ref decl, ref names, ref generics) => {
3581
+ let generics = generics. clean ( cx) ;
3566
3582
ForeignFunctionItem ( Function {
3567
- decl : ( & * * decl, & names[ ..] ) . clean ( cx) ,
3568
- generics : generics. clean ( cx) ,
3583
+ decl : enter_impl_trait ( cx, & generics. params , || {
3584
+ ( & * * decl, & names[ ..] ) . clean ( cx)
3585
+ } ) ,
3586
+ generics,
3569
3587
unsafety : hir:: Unsafety :: Unsafe ,
3570
3588
abi : Abi :: Rust ,
3571
3589
constness : hir:: Constness :: NotConst ,
@@ -3867,6 +3885,29 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
3867
3885
once ( crate_name) . chain ( relative) . collect ( )
3868
3886
}
3869
3887
3888
+ pub fn enter_impl_trait < F , R > ( cx : & DocContext , gps : & [ GenericParam ] , f : F ) -> R
3889
+ where
3890
+ F : FnOnce ( ) -> R ,
3891
+ {
3892
+ let bounds = gps. iter ( )
3893
+ . filter_map ( |p| {
3894
+ if let GenericParam :: Type ( ref tp) = * p {
3895
+ if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
3896
+ return Some ( ( tp. did , tp. bounds . clone ( ) ) ) ;
3897
+ }
3898
+ }
3899
+
3900
+ None
3901
+ } )
3902
+ . collect :: < FxHashMap < DefId , Vec < TyParamBound > > > ( ) ;
3903
+
3904
+ let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , bounds) ;
3905
+ let r = f ( ) ;
3906
+ assert ! ( cx. impl_trait_bounds. borrow( ) . is_empty( ) ) ;
3907
+ * cx. impl_trait_bounds . borrow_mut ( ) = old_bounds;
3908
+ r
3909
+ }
3910
+
3870
3911
// Start of code copied from rust-clippy
3871
3912
3872
3913
pub fn get_trait_def_id ( tcx : & TyCtxt , path : & [ & str ] , use_local : bool ) -> Option < DefId > {
0 commit comments