@@ -237,13 +237,22 @@ impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime {
237237 }
238238}
239239
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 ( ) } ,
247256 }
248257}
249258
@@ -392,7 +401,7 @@ impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> {
392401 fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Term {
393402 match self {
394403 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) ) ,
396405 }
397406 }
398407}
@@ -403,7 +412,7 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
403412 hir:: Term :: Ty ( ty) => Term :: Type ( clean_ty ( ty, cx) ) ,
404413 hir:: Term :: Const ( c) => {
405414 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) )
407416 }
408417 }
409418 }
@@ -1468,8 +1477,10 @@ fn maybe_expand_private_type_alias<'tcx>(
14681477 _ => None ,
14691478 } ) ;
14701479 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+ ) ;
14731484 }
14741485 // FIXME(const_generics_defaults)
14751486 indices. consts += 1 ;
@@ -1764,35 +1775,26 @@ pub(crate) fn clean_middle_ty<'tcx>(
17641775 }
17651776}
17661777
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)
17821781}
17831782
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+ )
17931790}
17941791
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 {
17961798 let what_rustc_thinks =
17971799 Item :: from_def_id_and_parts ( def_id, Some ( name) , StructFieldItem ( ty) , cx) ;
17981800 if is_field_vis_inherited ( cx. tcx , def_id) {
@@ -1830,27 +1832,27 @@ impl<'tcx> Clean<'tcx, VariantStruct> for rustc_hir::VariantData<'tcx> {
18301832 fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> VariantStruct {
18311833 VariantStruct {
18321834 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 ( ) ,
18341836 }
18351837 }
18361838}
18371839
18381840impl < ' tcx > Clean < ' tcx , Vec < Item > > for hir:: VariantData < ' tcx > {
18391841 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 ( )
18411843 }
18421844}
18431845
18441846impl < ' tcx > Clean < ' tcx , Item > for ty:: VariantDef {
18451847 fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
18461848 let kind = match self . ctor_kind {
18471849 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+ ) ,
18511853 CtorKind :: Fictive => Variant :: Struct ( VariantStruct {
18521854 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 ( ) ,
18541856 } ) ,
18551857 } ;
18561858 let what_rustc_thinks =
@@ -1894,7 +1896,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
18941896 }
18951897 hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
18961898 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) ) ) ,
18981900 hir:: GenericArg :: Infer ( _inf) => GenericArg :: Infer ,
18991901 } )
19001902 . collect :: < Vec < _ > > ( )
@@ -1970,12 +1972,12 @@ fn clean_maybe_renamed_item<'tcx>(
19701972 } ) ,
19711973 ItemKind :: Union ( ref variant_data, generics) => UnionItem ( Union {
19721974 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 ( ) ,
19741976 } ) ,
19751977 ItemKind :: Struct ( ref variant_data, generics) => StructItem ( Struct {
19761978 struct_type : CtorKind :: from_hir ( variant_data) ,
19771979 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 ( ) ,
19791981 } ) ,
19801982 ItemKind :: Impl ( impl_) => return clean_impl ( impl_, item. hir_id ( ) , cx) ,
19811983 // proc macros can have a name set by attributes
0 commit comments