@@ -273,6 +273,7 @@ pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'t
273273 Some ( def_id) ,
274274 None ,
275275 ) ,
276+ generics : Box :: new ( Generics :: default ( ) ) ,
276277 kind : ConstantKind :: Anonymous { body : constant. value . body } ,
277278 }
278279}
@@ -284,6 +285,7 @@ pub(crate) fn clean_middle_const<'tcx>(
284285 // FIXME: instead of storing the stringified expression, store `self` directly instead.
285286 Constant {
286287 type_ : clean_middle_ty ( constant. map_bound ( |c| c. ty ( ) ) , cx, None , None ) ,
288+ generics : Box :: new ( Generics :: default ( ) ) ,
287289 kind : ConstantKind :: TyConst { expr : constant. skip_binder ( ) . to_string ( ) . into ( ) } ,
288290 }
289291}
@@ -1188,11 +1190,18 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
11881190 let local_did = trait_item. owner_id . to_def_id ( ) ;
11891191 cx. with_param_env ( local_did, |cx| {
11901192 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+ }
11961205 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
11971206 let m = clean_function ( cx, sig, trait_item. generics , FunctionArgs :: Body ( body) ) ;
11981207 MethodItem ( m, None )
@@ -1237,8 +1246,9 @@ pub(crate) fn clean_impl_item<'tcx>(
12371246 cx. with_param_env ( local_did, |cx| {
12381247 let inner = match impl_. kind {
12391248 hir:: ImplItemKind :: Const ( ty, expr) => {
1249+ let generics = clean_generics ( impl_. generics , cx) ;
12401250 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)
12421252 }
12431253 hir:: ImplItemKind :: Fn ( ref sig, body) => {
12441254 let m = clean_function ( cx, sig, impl_. generics , FunctionArgs :: Body ( body) ) ;
@@ -1279,14 +1289,21 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
12791289 None ,
12801290 ) ;
12811291
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+
12821299 let provided = match assoc_item. container {
12831300 ty:: ImplContainer => true ,
12841301 ty:: TraitContainer => tcx. defaultness ( assoc_item. def_id ) . has_value ( ) ,
12851302 } ;
12861303 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 } )
12881305 } else {
1289- TyAssocConstItem ( ty)
1306+ TyAssocConstItem ( generics , ty)
12901307 }
12911308 }
12921309 ty:: AssocKind :: Fn => {
@@ -1379,34 +1396,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13791396 tcx. generics_of ( assoc_item. def_id ) ,
13801397 ty:: GenericPredicates { parent : None , predicates } ,
13811398 ) ;
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) ;
14101400
14111401 if let ty:: TraitContainer = assoc_item. container {
14121402 // Move bounds that are (likely) directly attached to the associated type
@@ -2603,9 +2593,9 @@ fn clean_maybe_renamed_item<'tcx>(
26032593 ItemKind :: Static ( ty, mutability, body_id) => {
26042594 StaticItem ( Static { type_ : clean_ty ( ty, cx) , mutability, expr : Some ( body_id) } )
26052595 }
2606- // FIXME(fmease): rustdoc integration
2607- ItemKind :: Const ( ty, _generics, body_id) => ConstantItem ( Constant {
2596+ ItemKind :: Const ( ty, generics, body_id) => ConstantItem ( Constant {
26082597 type_ : clean_ty ( ty, cx) ,
2598+ generics : Box :: new ( clean_generics ( generics, cx) ) ,
26092599 kind : ConstantKind :: Local { body : body_id, def_id } ,
26102600 } ) ,
26112601 ItemKind :: OpaqueTy ( ref ty) => OpaqueTyItem ( OpaqueTy {
0 commit comments