@@ -273,6 +273,7 @@ pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'t
273
273
Some ( def_id) ,
274
274
None ,
275
275
) ,
276
+ generics : Box :: new ( Generics :: default ( ) ) ,
276
277
kind : ConstantKind :: Anonymous { body : constant. value . body } ,
277
278
}
278
279
}
@@ -284,6 +285,7 @@ pub(crate) fn clean_middle_const<'tcx>(
284
285
// FIXME: instead of storing the stringified expression, store `self` directly instead.
285
286
Constant {
286
287
type_ : clean_middle_ty ( constant. map_bound ( |c| c. ty ( ) ) , cx, None , None ) ,
288
+ generics : Box :: new ( Generics :: default ( ) ) ,
287
289
kind : ConstantKind :: TyConst { expr : constant. skip_binder ( ) . to_string ( ) . into ( ) } ,
288
290
}
289
291
}
@@ -1188,11 +1190,18 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1188
1190
let local_did = trait_item. owner_id . to_def_id ( ) ;
1189
1191
cx. with_param_env ( local_did, |cx| {
1190
1192
let inner = match trait_item. kind {
1191
- hir:: TraitItemKind :: Const ( ty, Some ( default) ) => AssocConstItem (
1192
- clean_ty ( ty, cx) ,
1193
- ConstantKind :: Local { def_id : local_did, body : default } ,
1194
- ) ,
1195
- hir:: TraitItemKind :: Const ( ty, None ) => TyAssocConstItem ( clean_ty ( ty, cx) ) ,
1193
+ hir:: TraitItemKind :: Const ( ty, Some ( default) ) => {
1194
+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1195
+ AssocConstItem (
1196
+ Box :: new ( generics) ,
1197
+ clean_ty ( ty, cx) ,
1198
+ ConstantKind :: Local { def_id : local_did, body : default } ,
1199
+ )
1200
+ }
1201
+ hir:: TraitItemKind :: Const ( ty, None ) => {
1202
+ let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1203
+ TyAssocConstItem ( Box :: new ( generics) , clean_ty ( ty, cx) )
1204
+ }
1196
1205
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
1197
1206
let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
1198
1207
MethodItem ( m, None )
@@ -1237,8 +1246,9 @@ pub(crate) fn clean_impl_item<'tcx>(
1237
1246
cx. with_param_env ( local_did, |cx| {
1238
1247
let inner = match impl_. kind {
1239
1248
hir:: ImplItemKind :: Const ( ty, expr) => {
1249
+ let generics = clean_generics ( impl_. generics , cx) ;
1240
1250
let default = ConstantKind :: Local { def_id : local_did, body : expr } ;
1241
- AssocConstItem ( clean_ty ( ty, cx) , default)
1251
+ AssocConstItem ( Box :: new ( generics ) , clean_ty ( ty, cx) , default)
1242
1252
}
1243
1253
hir:: ImplItemKind :: Fn ( ref sig, body) => {
1244
1254
let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
@@ -1279,14 +1289,21 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1279
1289
None ,
1280
1290
) ;
1281
1291
1292
+ let mut generics = Box :: new ( clean_ty_generics (
1293
+ cx,
1294
+ tcx. generics_of ( assoc_item. def_id ) ,
1295
+ tcx. explicit_predicates_of ( assoc_item. def_id ) ,
1296
+ ) ) ;
1297
+ simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
1298
+
1282
1299
let provided = match assoc_item. container {
1283
1300
ty:: ImplContainer => true ,
1284
1301
ty:: TraitContainer => tcx. defaultness ( assoc_item. def_id ) . has_value ( ) ,
1285
1302
} ;
1286
1303
if provided {
1287
- AssocConstItem ( ty, ConstantKind :: Extern { def_id : assoc_item. def_id } )
1304
+ AssocConstItem ( generics , ty, ConstantKind :: Extern { def_id : assoc_item. def_id } )
1288
1305
} else {
1289
- TyAssocConstItem ( ty)
1306
+ TyAssocConstItem ( generics , ty)
1290
1307
}
1291
1308
}
1292
1309
ty:: AssocKind :: Fn => {
@@ -1379,34 +1396,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1379
1396
tcx. generics_of ( assoc_item. def_id ) ,
1380
1397
ty:: GenericPredicates { parent : None , predicates } ,
1381
1398
) ;
1382
- // Move bounds that are (likely) directly attached to the parameters of the
1383
- // (generic) associated type from the where clause to the respective parameter.
1384
- // There is no guarantee that this is what the user actually wrote but we have
1385
- // no way of knowing.
1386
- let mut where_predicates = ThinVec :: new ( ) ;
1387
- for mut pred in generics. where_predicates {
1388
- if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1389
- && let Some ( GenericParamDef {
1390
- kind : GenericParamDefKind :: Type { bounds : param_bounds, .. } ,
1391
- ..
1392
- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1393
- {
1394
- param_bounds. append ( bounds) ;
1395
- } else if let WherePredicate :: RegionPredicate { lifetime : Lifetime ( arg) , bounds } = & mut pred
1396
- && let Some ( GenericParamDef {
1397
- kind : GenericParamDefKind :: Lifetime { outlives : param_bounds } ,
1398
- ..
1399
- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1400
- {
1401
- param_bounds. extend ( bounds. drain ( ..) . map ( |bound| match bound {
1402
- GenericBound :: Outlives ( lifetime) => lifetime,
1403
- _ => unreachable ! ( ) ,
1404
- } ) ) ;
1405
- } else {
1406
- where_predicates. push ( pred) ;
1407
- }
1408
- }
1409
- generics. where_predicates = where_predicates;
1399
+ simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
1410
1400
1411
1401
if let ty:: TraitContainer = assoc_item. container {
1412
1402
// Move bounds that are (likely) directly attached to the associated type
@@ -2603,9 +2593,9 @@ fn clean_maybe_renamed_item<'tcx>(
2603
2593
ItemKind :: Static ( ty, mutability, body_id) => {
2604
2594
StaticItem ( Static { type_ : clean_ty ( ty, cx) , mutability, expr : Some ( body_id) } )
2605
2595
}
2606
- // FIXME(fmease): rustdoc integration
2607
- ItemKind :: Const ( ty, _generics, body_id) => ConstantItem ( Constant {
2596
+ ItemKind :: Const ( ty, generics, body_id) => ConstantItem ( Constant {
2608
2597
type_ : clean_ty ( ty, cx) ,
2598
+ generics : Box :: new ( clean_generics ( generics, cx) ) ,
2609
2599
kind : ConstantKind :: Local { body : body_id, def_id } ,
2610
2600
} ) ,
2611
2601
ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
0 commit comments