@@ -1729,8 +1729,18 @@ pub struct Generics {
1729
1729
1730
1730
impl Clean < Generics > for hir:: Generics {
1731
1731
fn clean ( & self , cx : & DocContext ) -> Generics {
1732
+ let mut params = Vec :: with_capacity ( self . params . len ( ) ) ;
1733
+ for p in & self . params {
1734
+ let p = p. clean ( cx) ;
1735
+ if let GenericParam :: Type ( ref tp) = p {
1736
+ if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
1737
+ cx. impl_trait_bounds . borrow_mut ( ) . insert ( tp. did , tp. bounds . clone ( ) ) ;
1738
+ }
1739
+ }
1740
+ params. push ( p) ;
1741
+ }
1732
1742
let mut g = Generics {
1733
- params : self . params . clean ( cx ) ,
1743
+ params,
1734
1744
where_predicates : self . where_clause . predicates . clean ( cx)
1735
1745
} ;
1736
1746
@@ -1843,9 +1853,11 @@ pub struct Method {
1843
1853
1844
1854
impl < ' a > Clean < Method > for ( & ' a hir:: MethodSig , & ' a hir:: Generics , hir:: BodyId ) {
1845
1855
fn clean ( & self , cx : & DocContext ) -> Method {
1846
- let generics = self . 1 . clean ( cx) ;
1856
+ let ( generics, decl) = enter_impl_trait ( cx, || {
1857
+ ( self . 1 . clean ( cx) , ( & * self . 0 . decl , self . 2 ) . clean ( cx) )
1858
+ } ) ;
1847
1859
Method {
1848
- decl : enter_impl_trait ( cx , & generics . params , || ( & * self . 0 . decl , self . 2 ) . clean ( cx ) ) ,
1860
+ decl,
1849
1861
generics,
1850
1862
unsafety : self . 0 . unsafety ,
1851
1863
constness : self . 0 . constness ,
@@ -1873,8 +1885,9 @@ pub struct Function {
1873
1885
1874
1886
impl Clean < Item > for doctree:: Function {
1875
1887
fn clean ( & self , cx : & DocContext ) -> Item {
1876
- let generics = self . generics . clean ( cx) ;
1877
- let decl = enter_impl_trait ( cx, & generics. params , || ( & self . decl , self . body ) . clean ( cx) ) ;
1888
+ let ( generics, decl) = enter_impl_trait ( cx, || {
1889
+ ( self . generics . clean ( cx) , ( & self . decl , self . body ) . clean ( cx) )
1890
+ } ) ;
1878
1891
Item {
1879
1892
name : Some ( self . name . clean ( cx) ) ,
1880
1893
attrs : self . attrs . clean ( cx) ,
@@ -2113,12 +2126,12 @@ impl Clean<Item> for hir::TraitItem {
2113
2126
MethodItem ( ( sig, & self . generics , body) . clean ( cx) )
2114
2127
}
2115
2128
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Required ( ref names) ) => {
2116
- let generics = self . generics . clean ( cx) ;
2129
+ let ( generics, decl) = enter_impl_trait ( cx, || {
2130
+ ( self . generics . clean ( cx) , ( & * sig. decl , & names[ ..] ) . clean ( cx) )
2131
+ } ) ;
2117
2132
TyMethodItem ( TyMethod {
2118
2133
unsafety : sig. unsafety . clone ( ) ,
2119
- decl : enter_impl_trait ( cx, & generics. params , || {
2120
- ( & * sig. decl , & names[ ..] ) . clean ( cx)
2121
- } ) ,
2134
+ decl,
2122
2135
generics,
2123
2136
abi : sig. abi
2124
2137
} )
@@ -3389,12 +3402,12 @@ pub struct BareFunctionDecl {
3389
3402
3390
3403
impl Clean < BareFunctionDecl > for hir:: BareFnTy {
3391
3404
fn clean ( & self , cx : & DocContext ) -> BareFunctionDecl {
3392
- let generic_params = self . generic_params . clean ( cx) ;
3405
+ let ( generic_params, decl) = enter_impl_trait ( cx, || {
3406
+ ( self . generic_params . clean ( cx) , ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx) )
3407
+ } ) ;
3393
3408
BareFunctionDecl {
3394
3409
unsafety : self . unsafety ,
3395
- decl : enter_impl_trait ( cx, & generic_params, || {
3396
- ( & * self . decl , & self . arg_names [ ..] ) . clean ( cx)
3397
- } ) ,
3410
+ decl,
3398
3411
generic_params,
3399
3412
abi : self . abi ,
3400
3413
}
@@ -3696,11 +3709,11 @@ impl Clean<Item> for hir::ForeignItem {
3696
3709
fn clean ( & self , cx : & DocContext ) -> Item {
3697
3710
let inner = match self . node {
3698
3711
hir:: ForeignItemFn ( ref decl, ref names, ref generics) => {
3699
- let generics = generics. clean ( cx) ;
3712
+ let ( generics, decl) = enter_impl_trait ( cx, || {
3713
+ ( generics. clean ( cx) , ( & * * decl, & names[ ..] ) . clean ( cx) )
3714
+ } ) ;
3700
3715
ForeignFunctionItem ( Function {
3701
- decl : enter_impl_trait ( cx, & generics. params , || {
3702
- ( & * * decl, & names[ ..] ) . clean ( cx)
3703
- } ) ,
3716
+ decl,
3704
3717
generics,
3705
3718
unsafety : hir:: Unsafety :: Unsafe ,
3706
3719
abi : Abi :: Rust ,
@@ -4003,23 +4016,11 @@ pub fn def_id_to_path(cx: &DocContext, did: DefId, name: Option<String>) -> Vec<
4003
4016
once ( crate_name) . chain ( relative) . collect ( )
4004
4017
}
4005
4018
4006
- pub fn enter_impl_trait < F , R > ( cx : & DocContext , gps : & [ GenericParam ] , f : F ) -> R
4019
+ pub fn enter_impl_trait < F , R > ( cx : & DocContext , f : F ) -> R
4007
4020
where
4008
4021
F : FnOnce ( ) -> R ,
4009
4022
{
4010
- let bounds = gps. iter ( )
4011
- . filter_map ( |p| {
4012
- if let GenericParam :: Type ( ref tp) = * p {
4013
- if tp. synthetic == Some ( hir:: SyntheticTyParamKind :: ImplTrait ) {
4014
- return Some ( ( tp. did , tp. bounds . clone ( ) ) ) ;
4015
- }
4016
- }
4017
-
4018
- None
4019
- } )
4020
- . collect :: < FxHashMap < DefId , Vec < TyParamBound > > > ( ) ;
4021
-
4022
- let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , bounds) ;
4023
+ let old_bounds = mem:: replace ( & mut * cx. impl_trait_bounds . borrow_mut ( ) , Default :: default ( ) ) ;
4023
4024
let r = f ( ) ;
4024
4025
assert ! ( cx. impl_trait_bounds. borrow( ) . is_empty( ) ) ;
4025
4026
* cx. impl_trait_bounds . borrow_mut ( ) = old_bounds;
0 commit comments