@@ -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,16 +1775,6 @@ 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
1778
pub ( crate ) fn clean_field < ' tcx > ( field : & hir:: FieldDef < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Item {
1778
1779
let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) . to_def_id ( ) ;
1779
1780
clean_field_with_def_id ( def_id, field. ident . name , clean_ty ( field. ty , cx) , cx)
@@ -1895,7 +1896,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
1895
1896
}
1896
1897
hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
1897
1898
hir:: GenericArg :: Type ( ty) => GenericArg :: Type ( clean_ty ( ty, cx) ) ,
1898
- hir:: GenericArg :: Const ( ct) => GenericArg :: Const ( Box :: new ( ct . clean ( cx) ) ) ,
1899
+ hir:: GenericArg :: Const ( ct) => GenericArg :: Const ( Box :: new ( clean_const ( ct , cx) ) ) ,
1899
1900
hir:: GenericArg :: Infer ( _inf) => GenericArg :: Infer ,
1900
1901
} )
1901
1902
. collect :: < Vec < _ > > ( )
0 commit comments