@@ -1201,21 +1201,19 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1201
1201
}
1202
1202
1203
1203
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.
1213
1204
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.
1219
1217
let mut bounds = generics
1220
1218
. where_predicates
1221
1219
. drain_filter ( |pred| match * pred {
@@ -1273,6 +1271,24 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1273
1271
}
1274
1272
None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
1275
1273
}
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;
1276
1292
1277
1293
if tcx. impl_defaultness ( assoc_item. def_id ) . has_value ( ) {
1278
1294
AssocTypeItem (
0 commit comments