@@ -1201,21 +1201,19 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
12011201 }
12021202
12031203 if let ty:: TraitContainer = assoc_item. container {
1204- // FIXME(fmease): `tcx.explicit_item_bounds` does not contain the bounds of GATs,
1205- // e.g. the bounds `Copy`, `Display` & (implicitly) `Sized` in
1206- // `type Assoc<T: Copy> where T: Display`. This also means that we
1207- // later incorrectly render `where T: ?Sized`.
1208- //
1209- // The result of `tcx.explicit_predicates_of` *does* contain them but
1210- // it does not contain the other bounds / predicates we need.
1211- // Either merge those two interned lists somehow or refactor
1212- // `clean_ty_generics` to call `explicit_item_bounds` by itself.
12131204 let bounds = tcx. explicit_item_bounds ( assoc_item. def_id ) ;
1214- let predicates = ty:: GenericPredicates { parent : None , predicates : bounds } ;
1215- let mut generics =
1216- clean_ty_generics ( cx, tcx. generics_of ( assoc_item. def_id ) , predicates) ;
1217- // Filter out the bounds that are (likely?) directly attached to the associated type,
1218- // as opposed to being located in the where clause.
1205+ let predicates = tcx. explicit_predicates_of ( assoc_item. def_id ) . predicates ;
1206+ let predicates =
1207+ tcx. arena . alloc_from_iter ( bounds. into_iter ( ) . chain ( predicates) . copied ( ) ) ;
1208+ let mut generics = clean_ty_generics (
1209+ cx,
1210+ tcx. generics_of ( assoc_item. def_id ) ,
1211+ ty:: GenericPredicates { parent : None , predicates } ,
1212+ ) ;
1213+ // Move bounds that are (likely) directly attached to the associated type
1214+ // from the where clause to the associated type.
1215+ // There is no guarantee that this is what the user actually wrote but we have
1216+ // no way of knowing.
12191217 let mut bounds = generics
12201218 . where_predicates
12211219 . drain_filter ( |pred| match * pred {
@@ -1273,6 +1271,24 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
12731271 }
12741272 None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
12751273 }
1274+ // Move bounds that are (likely) directly attached to the parameters of the
1275+ // (generic) associated type from the where clause to the respective parameter.
1276+ // There is no guarantee that this is what the user actually wrote but we have
1277+ // no way of knowing.
1278+ let mut where_predicates = Vec :: new ( ) ;
1279+ for mut pred in generics. where_predicates {
1280+ if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1281+ && let Some ( GenericParamDef {
1282+ kind : GenericParamDefKind :: Type { bounds : param_bounds, .. } ,
1283+ ..
1284+ } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1285+ {
1286+ param_bounds. extend ( mem:: take ( bounds) ) ;
1287+ } else {
1288+ where_predicates. push ( pred) ;
1289+ }
1290+ }
1291+ generics. where_predicates = where_predicates;
12761292
12771293 if tcx. impl_defaultness ( assoc_item. def_id ) . has_value ( ) {
12781294 AssocTypeItem (
0 commit comments