@@ -237,13 +237,22 @@ impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime {
237
237
}
238
238
}
239
239
240
- impl < ' tcx > Clean < ' tcx , Constant > for hir:: ConstArg {
241
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Constant {
242
- let def_id = cx. tcx . hir ( ) . body_owner_def_id ( self . value . body ) . to_def_id ( ) ;
243
- Constant {
244
- type_ : clean_middle_ty ( cx. tcx . type_of ( def_id) , cx, Some ( def_id) ) ,
245
- kind : ConstantKind :: Anonymous { body : self . value . body } ,
246
- }
240
+ pub ( crate ) fn clean_const < ' tcx > ( constant : & hir:: ConstArg , cx : & mut DocContext < ' tcx > ) -> Constant {
241
+ let def_id = cx. tcx . hir ( ) . body_owner_def_id ( constant. value . body ) . to_def_id ( ) ;
242
+ Constant {
243
+ type_ : clean_middle_ty ( cx. tcx . type_of ( def_id) , cx, Some ( def_id) ) ,
244
+ kind : ConstantKind :: Anonymous { body : constant. value . body } ,
245
+ }
246
+ }
247
+
248
+ pub ( crate ) fn clean_middle_const < ' tcx > (
249
+ constant : ty:: Const < ' tcx > ,
250
+ cx : & mut DocContext < ' tcx > ,
251
+ ) -> Constant {
252
+ // FIXME: instead of storing the stringified expression, store `self` directly instead.
253
+ Constant {
254
+ type_ : clean_middle_ty ( constant. ty ( ) , cx, None ) ,
255
+ kind : ConstantKind :: TyConst { expr : constant. to_string ( ) } ,
247
256
}
248
257
}
249
258
@@ -392,7 +401,7 @@ impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> {
392
401
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Term {
393
402
match self {
394
403
ty:: Term :: Ty ( ty) => Term :: Type ( clean_middle_ty ( * ty, cx, None ) ) ,
395
- ty:: Term :: Const ( c) => Term :: Constant ( c . clean ( cx) ) ,
404
+ ty:: Term :: Const ( c) => Term :: Constant ( clean_middle_const ( * c , cx) ) ,
396
405
}
397
406
}
398
407
}
@@ -403,7 +412,7 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
403
412
hir:: Term :: Ty ( ty) => Term :: Type ( clean_ty ( ty, cx) ) ,
404
413
hir:: Term :: Const ( c) => {
405
414
let def_id = cx. tcx . hir ( ) . local_def_id ( c. hir_id ) ;
406
- Term :: Constant ( ty:: Const :: from_anon_const ( cx. tcx , def_id) . clean ( cx) )
415
+ Term :: Constant ( clean_middle_const ( ty:: Const :: from_anon_const ( cx. tcx , def_id) , cx) )
407
416
}
408
417
}
409
418
}
@@ -1468,8 +1477,10 @@ fn maybe_expand_private_type_alias<'tcx>(
1468
1477
_ => None ,
1469
1478
} ) ;
1470
1479
if let Some ( ct) = const_ {
1471
- substs
1472
- . insert ( const_param_def_id. to_def_id ( ) , SubstParam :: Constant ( ct. clean ( cx) ) ) ;
1480
+ substs. insert (
1481
+ const_param_def_id. to_def_id ( ) ,
1482
+ SubstParam :: Constant ( clean_const ( ct, cx) ) ,
1483
+ ) ;
1473
1484
}
1474
1485
// FIXME(const_generics_defaults)
1475
1486
indices. consts += 1 ;
@@ -1764,35 +1775,26 @@ pub(crate) fn clean_middle_ty<'tcx>(
1764
1775
}
1765
1776
}
1766
1777
1767
- impl < ' tcx > Clean < ' tcx , Constant > for ty:: Const < ' tcx > {
1768
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Constant {
1769
- // FIXME: instead of storing the stringified expression, store `self` directly instead.
1770
- Constant {
1771
- type_ : clean_middle_ty ( self . ty ( ) , cx, None ) ,
1772
- kind : ConstantKind :: TyConst { expr : self . to_string ( ) } ,
1773
- }
1774
- }
1775
- }
1776
-
1777
- impl < ' tcx > Clean < ' tcx , Item > for hir:: FieldDef < ' tcx > {
1778
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
1779
- let def_id = cx. tcx . hir ( ) . local_def_id ( self . hir_id ) . to_def_id ( ) ;
1780
- clean_field ( def_id, self . ident . name , clean_ty ( self . ty , cx) , cx)
1781
- }
1778
+ pub ( crate ) fn clean_field < ' tcx > ( field : & hir:: FieldDef < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Item {
1779
+ let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) . to_def_id ( ) ;
1780
+ clean_field_with_def_id ( def_id, field. ident . name , clean_ty ( field. ty , cx) , cx)
1782
1781
}
1783
1782
1784
- impl < ' tcx > Clean < ' tcx , Item > for ty:: FieldDef {
1785
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
1786
- clean_field (
1787
- self . did ,
1788
- self . name ,
1789
- clean_middle_ty ( cx. tcx . type_of ( self . did ) , cx, Some ( self . did ) ) ,
1790
- cx,
1791
- )
1792
- }
1783
+ pub ( crate ) fn clean_middle_field < ' tcx > ( field : & ty:: FieldDef , cx : & mut DocContext < ' tcx > ) -> Item {
1784
+ clean_field_with_def_id (
1785
+ field. did ,
1786
+ field. name ,
1787
+ clean_middle_ty ( cx. tcx . type_of ( field. did ) , cx, Some ( field. did ) ) ,
1788
+ cx,
1789
+ )
1793
1790
}
1794
1791
1795
- fn clean_field ( def_id : DefId , name : Symbol , ty : Type , cx : & mut DocContext < ' _ > ) -> Item {
1792
+ pub ( crate ) fn clean_field_with_def_id (
1793
+ def_id : DefId ,
1794
+ name : Symbol ,
1795
+ ty : Type ,
1796
+ cx : & mut DocContext < ' _ > ,
1797
+ ) -> Item {
1796
1798
let what_rustc_thinks =
1797
1799
Item :: from_def_id_and_parts ( def_id, Some ( name) , StructFieldItem ( ty) , cx) ;
1798
1800
if is_field_vis_inherited ( cx. tcx , def_id) {
@@ -1830,27 +1832,27 @@ impl<'tcx> Clean<'tcx, VariantStruct> for rustc_hir::VariantData<'tcx> {
1830
1832
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> VariantStruct {
1831
1833
VariantStruct {
1832
1834
struct_type : CtorKind :: from_hir ( self ) ,
1833
- fields : self . fields ( ) . iter ( ) . map ( |x| x . clean ( cx) ) . collect ( ) ,
1835
+ fields : self . fields ( ) . iter ( ) . map ( |x| clean_field ( x , cx) ) . collect ( ) ,
1834
1836
}
1835
1837
}
1836
1838
}
1837
1839
1838
1840
impl < ' tcx > Clean < ' tcx , Vec < Item > > for hir:: VariantData < ' tcx > {
1839
1841
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Vec < Item > {
1840
- self . fields ( ) . iter ( ) . map ( |x| x . clean ( cx) ) . collect ( )
1842
+ self . fields ( ) . iter ( ) . map ( |x| clean_field ( x , cx) ) . collect ( )
1841
1843
}
1842
1844
}
1843
1845
1844
1846
impl < ' tcx > Clean < ' tcx , Item > for ty:: VariantDef {
1845
1847
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
1846
1848
let kind = match self . ctor_kind {
1847
1849
CtorKind :: Const => Variant :: CLike ,
1848
- CtorKind :: Fn => {
1849
- Variant :: Tuple ( self . fields . iter ( ) . map ( |field| field . clean ( cx) ) . collect ( ) )
1850
- }
1850
+ CtorKind :: Fn => Variant :: Tuple (
1851
+ self . fields . iter ( ) . map ( |field| clean_middle_field ( field , cx) ) . collect ( ) ,
1852
+ ) ,
1851
1853
CtorKind :: Fictive => Variant :: Struct ( VariantStruct {
1852
1854
struct_type : CtorKind :: Fictive ,
1853
- fields : self . fields . iter ( ) . map ( |field| field . clean ( cx) ) . collect ( ) ,
1855
+ fields : self . fields . iter ( ) . map ( |field| clean_middle_field ( field , cx) ) . collect ( ) ,
1854
1856
} ) ,
1855
1857
} ;
1856
1858
let what_rustc_thinks =
@@ -1894,7 +1896,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
1894
1896
}
1895
1897
hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
1896
1898
hir:: GenericArg :: Type ( ty) => GenericArg :: Type ( clean_ty ( ty, cx) ) ,
1897
- hir:: GenericArg :: Const ( ct) => GenericArg :: Const ( Box :: new ( ct . clean ( cx) ) ) ,
1899
+ hir:: GenericArg :: Const ( ct) => GenericArg :: Const ( Box :: new ( clean_const ( ct , cx) ) ) ,
1898
1900
hir:: GenericArg :: Infer ( _inf) => GenericArg :: Infer ,
1899
1901
} )
1900
1902
. collect :: < Vec < _ > > ( )
@@ -1970,12 +1972,12 @@ fn clean_maybe_renamed_item<'tcx>(
1970
1972
} ) ,
1971
1973
ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
1972
1974
generics : generics. clean ( cx) ,
1973
- fields : variant_data. fields ( ) . iter ( ) . map ( |x| x . clean ( cx) ) . collect ( ) ,
1975
+ fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x , cx) ) . collect ( ) ,
1974
1976
} ) ,
1975
1977
ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
1976
1978
struct_type : CtorKind :: from_hir ( variant_data) ,
1977
1979
generics : generics. clean ( cx) ,
1978
- fields : variant_data. fields ( ) . iter ( ) . map ( |x| x . clean ( cx) ) . collect ( ) ,
1980
+ fields : variant_data. fields ( ) . iter ( ) . map ( |x| clean_field ( x , cx) ) . collect ( ) ,
1979
1981
} ) ,
1980
1982
ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
1981
1983
// proc macros can have a name set by attributes
0 commit comments