@@ -1755,8 +1755,18 @@ pub struct Generics {
1755
1755
1756
1756
impl Clean < Generics > for hir:: Generics {
1757
1757
fn clean ( & self , cx : & DocContext ) -> Generics {
1758
+ let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
1759
+ for p in & self . params {
1760
+ let p = p. clean ( cx) ;
1761
+ if let GenericParam :: Type ( ref tp) = p {
1762
+ if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
1763
+ cx. impl_trait_bounds . borrow_mut ( ) . insert ( tp. did , tp. bounds . clone ( ) ) ;
1764
+ }
1765
+ }
1766
+ params. push ( p) ;
1767
+ }
1758
1768
let mut g = Generics {
1759
- params : self . params . clean ( cx ) ,
1769
+ params,
1760
1770
where_predicates : self . where_clause . predicates . clean ( cx)
1761
1771
} ;
1762
1772
@@ -1869,9 +1879,11 @@ pub struct Method {
1869
1879
1870
1880
impl < ' a > Clean < Method > for ( & ' a hir:: MethodSig , & ' a hir:: Generics , hir:: BodyId ) {
1871
1881
fn clean ( & self , cx : & DocContext ) -> Method {
1872
- let generics = self . 1 . clean ( cx) ;
1882
+ let ( generics, decl) = enter_impl_trait ( cx, || {
1883
+ ( self . 1 . clean ( cx) , ( & * self . 0 . decl , self . 2 ) . clean ( cx) )
1884
+ } ) ;
1873
1885
Method {
1874
- decl : enter_impl_trait ( cx , & generics . params , || ( & * self . 0 . decl , self . 2 ) . clean ( cx ) ) ,
1886
+ decl,
1875
1887
generics,
1876
1888
unsafety : self . 0 . unsafety ,
1877
1889
constness : self . 0 . constness ,
@@ -1899,8 +1911,9 @@ pub struct Function {
1899
1911
1900
1912
impl Clean < Item > for doctree:: Function {
1901
1913
fn clean ( & self , cx : & DocContext ) -> Item {
1902
- let generics = self . generics . clean ( cx) ;
1903
- let decl = enter_impl_trait ( cx, & generics. params , || ( & self . decl , self . body ) . clean ( cx) ) ;
1914
+ let ( generics, decl) = enter_impl_trait ( cx, || {
1915
+ ( self . generics . clean ( cx) , ( & self . decl , self . body ) . clean ( cx) )
1916
+ } ) ;
1904
1917
Item {
1905
1918
name : Some ( self . name . clean ( cx) ) ,
1906
1919
attrs : self . attrs . clean ( cx) ,
@@ -2139,12 +2152,12 @@ impl Clean<Item> for hir::TraitItem {
2139
2152
MethodItem ( ( sig, & self . generics , body) . clean ( cx) )
2140
2153
}
2141
2154
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Required ( ref names) ) => {
2142
- let generics = self . generics . clean ( cx) ;
2155
+ let ( generics, decl) = enter_impl_trait ( cx, || {
2156
+ ( self . generics . clean ( cx) , ( & * sig. decl , & names[ ..] ) . clean ( cx) )
2157
+ } ) ;
2143
2158
TyMethodItem ( TyMethod {
2144
2159
unsafety : sig. unsafety . clone ( ) ,
2145
- decl : enter_impl_trait ( cx, & generics. params , || {
2146
- ( & * sig. decl , & names[ ..] ) . clean ( cx)
2147
- } ) ,
2160
+ decl,
2148
2161
generics,
2149
2162
abi : sig. abi
2150
2163
} )
@@ -3415,12 +3428,12 @@ pub struct BareFunctionDecl {
3415
3428
3416
3429
impl Clean < BareFunctionDecl > for hir:: BareFnTy {
3417
3430
fn clean ( & self , cx : & DocContext ) -> BareFunctionDecl {
3418
- let generic_params = self . generic_params . clean ( cx) ;
3431
+ let ( generic_params, decl) = enter_impl_trait ( cx, || {
3432
+ ( self . generic_params . clean ( cx) , ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx) )
3433
+ } ) ;
3419
3434
BareFunctionDecl {
3420
3435
unsafety : self . unsafety ,
3421
- decl : enter_impl_trait ( cx, & generic_params, || {
3422
- ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx)
3423
- } ) ,
3436
+ decl,
3424
3437
generic_params,
3425
3438
abi : self . abi ,
3426
3439
}
@@ -3722,11 +3735,11 @@ impl Clean<Item> for hir::ForeignItem {
3722
3735
fn clean ( & self , cx : & DocContext ) -> Item {
3723
3736
let inner = match self . node {
3724
3737
hir:: ForeignItemFn ( ref decl, ref names, ref generics) => {
3725
- let generics = generics. clean ( cx) ;
3738
+ let ( generics, decl) = enter_impl_trait ( cx, || {
3739
+ ( generics. clean ( cx) , ( & * * decl, & names[ ..] ) . clean ( cx) )
3740
+ } ) ;
3726
3741
ForeignFunctionItem ( Function {
3727
- decl : enter_impl_trait ( cx, & generics. params , || {
3728
- ( & * * decl, & names[ ..] ) . clean ( cx)
3729
- } ) ,
3742
+ decl,
3730
3743
generics,
3731
3744
unsafety : hir:: Unsafety :: Unsafe ,
3732
3745
abi : Abi :: Rust ,
@@ -4030,23 +4043,11 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
4030
4043
once ( crate_name) . chain ( relative) . collect ( )
4031
4044
}
4032
4045
4033
- pub fn enter_impl_trait < F , R > ( cx : & DocContext , gps : & [ GenericParam ] , f : F ) -> R
4046
+ pub fn enter_impl_trait < F , R > ( cx : & DocContext , f : F ) -> R
4034
4047
where
4035
4048
F : FnOnce ( ) -> R ,
4036
4049
{
4037
- let bounds = gps. iter ( )
4038
- . filter_map ( |p| {
4039
- if let GenericParam :: Type ( ref tp) = * p {
4040
- if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
4041
- return Some ( ( tp. did , tp. bounds . clone ( ) ) ) ;
4042
- }
4043
- }
4044
-
4045
- None
4046
- } )
4047
- . collect :: < FxHashMap < DefId , Vec < TyParamBound > > > ( ) ;
4048
-
4049
- let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , bounds) ;
4050
+ let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , Default :: default ( ) ) ;
4050
4051
let r = f ( ) ;
4051
4052
assert ! ( cx. impl_trait_bounds. borrow( ) . is_empty( ) ) ;
4052
4053
* cx. impl_trait_bounds . borrow_mut ( ) = old_bounds;
0 commit comments