@@ -256,6 +256,7 @@ pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'t
256256 Some ( def_id) ,
257257 None ,
258258 ) ,
259+ generics : Box :: new ( Generics :: default ( ) ) ,
259260 kind : ConstantKind :: Anonymous { body : constant. value . body } ,
260261 }
261262}
@@ -267,6 +268,7 @@ pub(crate) fn clean_middle_const<'tcx>(
267268 // FIXME: instead of storing the stringified expression, store `self` directly instead.
268269 Constant {
269270 type_ : clean_middle_ty ( constant. map_bound ( |c| c. ty ( ) ) , cx, None , None ) ,
271+ generics : Box :: new ( Generics :: default ( ) ) ,
270272 kind : ConstantKind :: TyConst { expr : constant. skip_binder ( ) . to_string ( ) . into ( ) } ,
271273 }
272274}
@@ -1159,11 +1161,20 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
11591161 let local_did = trait_item. owner_id . to_def_id ( ) ;
11601162 cx. with_param_env ( local_did, |cx| {
11611163 let inner = match trait_item. kind {
1162- hir:: TraitItemKind :: Const ( ty, Some ( default) ) => AssocConstItem (
1163- clean_ty ( ty, cx) ,
1164- ConstantKind :: Local { def_id : local_did, body : default } ,
1165- ) ,
1166- hir:: TraitItemKind :: Const ( ty, None ) => TyAssocConstItem ( clean_ty ( ty, cx) ) ,
1164+ hir:: TraitItemKind :: Const ( ty, Some ( default) ) => {
1165+ // FIXME(generic_consts): I don't think we need to / should `enter_impl_trait`
1166+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1167+ AssocConstItem (
1168+ Box :: new ( generics) ,
1169+ clean_ty ( ty, cx) ,
1170+ ConstantKind :: Local { def_id : local_did, body : default } ,
1171+ )
1172+ }
1173+ hir:: TraitItemKind :: Const ( ty, None ) => {
1174+ // FIXME(generic_consts): I don't think we need to / should `enter_impl_trait`
1175+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1176+ TyAssocConstItem ( Box :: new ( generics) , clean_ty ( ty, cx) )
1177+ }
11671178 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
11681179 let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
11691180 MethodItem ( m, None )
@@ -1208,8 +1219,9 @@ pub(crate) fn clean_impl_item<'tcx>(
12081219 cx. with_param_env ( local_did, |cx| {
12091220 let inner = match impl_. kind {
12101221 hir:: ImplItemKind :: Const ( ty, expr) => {
1222+ let generics = clean_generics ( impl_. generics , cx) ;
12111223 let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1212- AssocConstItem ( clean_ty ( ty, cx) , default)
1224+ AssocConstItem ( Box :: new ( generics ) , clean_ty ( ty, cx) , default)
12131225 }
12141226 hir:: ImplItemKind :: Fn ( ref sig, body) => {
12151227 let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
@@ -1250,14 +1262,21 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
12501262 None ,
12511263 ) ;
12521264
1265+ let mut generics = Box :: new ( clean_ty_generics (
1266+ cx,
1267+ tcx. generics_of ( assoc_item. def_id ) ,
1268+ tcx. explicit_predicates_of ( assoc_item. def_id ) ,
1269+ ) ) ;
1270+ simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
1271+
12531272 let provided = match assoc_item. container {
12541273 ty:: ImplContainer => true ,
12551274 ty:: TraitContainer => tcx. defaultness ( assoc_item. def_id ) . has_value ( ) ,
12561275 } ;
12571276 if provided {
1258- AssocConstItem ( ty, ConstantKind :: Extern { def_id : assoc_item. def_id } )
1277+ AssocConstItem ( generics , ty, ConstantKind :: Extern { def_id : assoc_item. def_id } )
12591278 } else {
1260- TyAssocConstItem ( ty)
1279+ TyAssocConstItem ( generics , ty)
12611280 }
12621281 }
12631282 ty:: AssocKind :: Fn => {
@@ -1348,34 +1367,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13481367 tcx. generics_of ( assoc_item. def_id ) ,
13491368 ty:: GenericPredicates { parent : None , predicates } ,
13501369 ) ;
1351- // Move bounds that are (likely) directly attached to the parameters of the
1352- // (generic) associated type from the where clause to the respective parameter.
1353- // There is no guarantee that this is what the user actually wrote but we have
1354- // no way of knowing.
1355- let mut where_predicates = ThinVec :: new ( ) ;
1356- for mut pred in generics. where_predicates {
1357- if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1358- && let Some ( GenericParamDef {
1359- kind : GenericParamDefKind :: Type { bounds : param_bounds, .. } ,
1360- ..
1361- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1362- {
1363- param_bounds. append ( bounds) ;
1364- } else if let WherePredicate :: RegionPredicate { lifetime : Lifetime ( arg) , bounds } = & mut pred
1365- && let Some ( GenericParamDef {
1366- kind : GenericParamDefKind :: Lifetime { outlives : param_bounds } ,
1367- ..
1368- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1369- {
1370- param_bounds. extend ( bounds. drain ( ..) . map ( |bound| match bound {
1371- GenericBound :: Outlives ( lifetime) => lifetime,
1372- _ => unreachable ! ( ) ,
1373- } ) ) ;
1374- } else {
1375- where_predicates. push ( pred) ;
1376- }
1377- }
1378- generics. where_predicates = where_predicates;
1370+ simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
13791371
13801372 if let ty:: TraitContainer = assoc_item. container {
13811373 // Move bounds that are (likely) directly attached to the associated type
@@ -2446,9 +2438,9 @@ fn clean_maybe_renamed_item<'tcx>(
24462438 ItemKind :: Static ( ty, mutability, body_id) => {
24472439 StaticItem ( Static { type_ : clean_ty ( ty, cx) , mutability, expr : Some ( body_id) } )
24482440 }
2449- // FIXME(fmease): rustdoc integration
2450- ItemKind :: Const ( ty, _generics, body_id) => ConstantItem ( Constant {
2441+ ItemKind :: Const ( ty, generics, body_id) => ConstantItem ( Constant {
24512442 type_ : clean_ty ( ty, cx) ,
2443+ generics : Box :: new ( clean_generics ( generics, cx) ) ,
24522444 kind : ConstantKind :: Local { body : body_id, def_id } ,
24532445 } ) ,
24542446 ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
0 commit comments