@@ -256,6 +256,7 @@ pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'t
256
256
Some ( def_id) ,
257
257
None ,
258
258
) ,
259
+ generics : Box :: new ( Generics :: default ( ) ) ,
259
260
kind : ConstantKind :: Anonymous { body : constant. value . body } ,
260
261
}
261
262
}
@@ -267,6 +268,7 @@ pub(crate) fn clean_middle_const<'tcx>(
267
268
// FIXME: instead of storing the stringified expression, store `self` directly instead.
268
269
Constant {
269
270
type_ : clean_middle_ty ( constant. map_bound ( |c| c. ty ( ) ) , cx, None , None ) ,
271
+ generics : Box :: new ( Generics :: default ( ) ) ,
270
272
kind : ConstantKind :: TyConst { expr : constant. skip_binder ( ) . to_string ( ) . into ( ) } ,
271
273
}
272
274
}
@@ -1159,11 +1161,20 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1159
1161
let local_did = trait_item. owner_id . to_def_id ( ) ;
1160
1162
cx. with_param_env ( local_did, |cx| {
1161
1163
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
+ }
1167
1178
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
1168
1179
let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
1169
1180
MethodItem ( m, None )
@@ -1208,8 +1219,9 @@ pub(crate) fn clean_impl_item<'tcx>(
1208
1219
cx. with_param_env ( local_did, |cx| {
1209
1220
let inner = match impl_. kind {
1210
1221
hir:: ImplItemKind :: Const ( ty, expr) => {
1222
+ let generics = clean_generics ( impl_. generics , cx) ;
1211
1223
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)
1213
1225
}
1214
1226
hir:: ImplItemKind :: Fn ( ref sig, body) => {
1215
1227
let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
@@ -1250,14 +1262,21 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1250
1262
None ,
1251
1263
) ;
1252
1264
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
+
1253
1272
let provided = match assoc_item. container {
1254
1273
ty:: ImplContainer => true ,
1255
1274
ty:: TraitContainer => tcx. defaultness ( assoc_item. def_id ) . has_value ( ) ,
1256
1275
} ;
1257
1276
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 } )
1259
1278
} else {
1260
- TyAssocConstItem ( ty)
1279
+ TyAssocConstItem ( generics , ty)
1261
1280
}
1262
1281
}
1263
1282
ty:: AssocKind :: Fn => {
@@ -1348,34 +1367,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1348
1367
tcx. generics_of ( assoc_item. def_id ) ,
1349
1368
ty:: GenericPredicates { parent : None , predicates } ,
1350
1369
) ;
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) ;
1379
1371
1380
1372
if let ty:: TraitContainer = assoc_item. container {
1381
1373
// Move bounds that are (likely) directly attached to the associated type
@@ -2446,9 +2438,9 @@ fn clean_maybe_renamed_item<'tcx>(
2446
2438
ItemKind :: Static ( ty, mutability, body_id) => {
2447
2439
StaticItem ( Static { type_ : clean_ty ( ty, cx) , mutability, expr : Some ( body_id) } )
2448
2440
}
2449
- // FIXME(fmease): rustdoc integration
2450
- ItemKind :: Const ( ty, _generics, body_id) => ConstantItem ( Constant {
2441
+ ItemKind :: Const ( ty, generics, body_id) => ConstantItem ( Constant {
2451
2442
type_ : clean_ty ( ty, cx) ,
2443
+ generics : Box :: new ( clean_generics ( generics, cx) ) ,
2452
2444
kind : ConstantKind :: Local { body : body_id, def_id } ,
2453
2445
} ) ,
2454
2446
ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
0 commit comments