@@ -601,7 +601,7 @@ pub(crate) fn clean_generics<'tcx>(
601
601
} )
602
602
. collect :: < Vec < _ > > ( ) ;
603
603
604
- let mut params = Vec :: with_capacity ( gens. params . len ( ) ) ;
604
+ let mut params = ThinVec :: with_capacity ( gens. params . len ( ) ) ;
605
605
for p in gens. params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
606
606
let p = clean_generic_param ( cx, Some ( gens) , p) ;
607
607
params. push ( p) ;
@@ -675,7 +675,7 @@ fn clean_ty_generics<'tcx>(
675
675
}
676
676
ty:: GenericParamDefKind :: Const { .. } => Some ( clean_generic_param_def ( param, cx) ) ,
677
677
} )
678
- . collect :: < Vec < GenericParamDef > > ( ) ;
678
+ . collect :: < ThinVec < GenericParamDef > > ( ) ;
679
679
680
680
// param index -> [(trait DefId, associated type name & generics, type, higher-ranked params)]
681
681
let mut impl_trait_proj =
@@ -1080,7 +1080,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
1080
1080
hir:: TraitItemKind :: Type ( bounds, None ) => {
1081
1081
let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
1082
1082
let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1083
- TyAssocTypeItem ( Box :: new ( generics) , bounds)
1083
+ TyAssocTypeItem ( generics, bounds)
1084
1084
}
1085
1085
} ;
1086
1086
Item :: from_def_id_and_parts ( local_did, Some ( trait_item. ident . name ) , inner, cx)
@@ -1211,56 +1211,47 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1211
1211
tcx. generics_of ( assoc_item. def_id ) ,
1212
1212
ty:: GenericPredicates { parent : None , predicates } ,
1213
1213
) ;
1214
- // Move bounds that are (likely) directly attached to the associated type
1215
- // from the where clause to the associated type.
1216
- // There is no guarantee that this is what the user actually wrote but we have
1217
- // no way of knowing.
1218
- let mut bounds = generics
1219
- . where_predicates
1220
- . drain_filter ( |pred| match * pred {
1221
- WherePredicate :: BoundPredicate {
1222
- ty : QPath ( box QPathData { ref assoc, ref self_type, ref trait_, .. } ) ,
1223
- ..
1224
- } => {
1225
- if assoc. name != my_name {
1226
- return false ;
1227
- }
1228
- if trait_. def_id ( ) != assoc_item. container_id ( tcx) {
1229
- return false ;
1230
- }
1231
- match * self_type {
1232
- Generic ( ref s) if * s == kw:: SelfUpper => { }
1233
- _ => return false ,
1234
- }
1235
- match & assoc. args {
1236
- GenericArgs :: AngleBracketed { args, bindings } => {
1237
- if !bindings. is_empty ( )
1238
- || generics
1239
- . params
1240
- . iter ( )
1241
- . zip ( args. iter ( ) )
1242
- . any ( |( param, arg) | !param_eq_arg ( param, arg) )
1243
- {
1244
- return false ;
1245
- }
1246
- }
1247
- GenericArgs :: Parenthesized { .. } => {
1248
- // The only time this happens is if we're inside the rustdoc for Fn(),
1249
- // which only has one associated type, which is not a GAT, so whatever.
1214
+ // Filter out the bounds that are (likely?) directly attached to the associated type,
1215
+ // as opposed to being located in the where clause.
1216
+ let mut bounds: Vec < GenericBound > = Vec :: new ( ) ;
1217
+ generics. where_predicates . retain_mut ( |pred| match * pred {
1218
+ WherePredicate :: BoundPredicate {
1219
+ ty : QPath ( box QPathData { ref assoc, ref self_type, ref trait_, .. } ) ,
1220
+ bounds : ref mut pred_bounds,
1221
+ ..
1222
+ } => {
1223
+ if assoc. name != my_name {
1224
+ return true ;
1225
+ }
1226
+ if trait_. def_id ( ) != assoc_item. container_id ( tcx) {
1227
+ return true ;
1228
+ }
1229
+ match * self_type {
1230
+ Generic ( ref s) if * s == kw:: SelfUpper => { }
1231
+ _ => return true ,
1232
+ }
1233
+ match & assoc. args {
1234
+ GenericArgs :: AngleBracketed { args, bindings } => {
1235
+ if !bindings. is_empty ( )
1236
+ || generics
1237
+ . params
1238
+ . iter ( )
1239
+ . zip ( args. iter ( ) )
1240
+ . any ( |( param, arg) | !param_eq_arg ( param, arg) )
1241
+ {
1242
+ return true ;
1250
1243
}
1251
1244
}
1252
- true
1253
- }
1254
- _ => false ,
1255
- } )
1256
- . flat_map ( |pred| {
1257
- if let WherePredicate :: BoundPredicate { bounds, .. } = pred {
1258
- bounds
1259
- } else {
1260
- unreachable ! ( )
1245
+ GenericArgs :: Parenthesized { .. } => {
1246
+ // The only time this happens is if we're inside the rustdoc for Fn(),
1247
+ // which only has one associated type, which is not a GAT, so whatever.
1248
+ }
1261
1249
}
1262
- } )
1263
- . collect :: < Vec < _ > > ( ) ;
1250
+ bounds. extend ( mem:: replace ( pred_bounds, Vec :: new ( ) ) ) ;
1251
+ false
1252
+ }
1253
+ _ => true ,
1254
+ } ) ;
1264
1255
// Our Sized/?Sized bound didn't get handled when creating the generics
1265
1256
// because we didn't actually get our whole set of bounds until just now
1266
1257
// (some of them may have come from the trait). If we do have a sized
@@ -1276,7 +1267,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1276
1267
// (generic) associated type from the where clause to the respective parameter.
1277
1268
// There is no guarantee that this is what the user actually wrote but we have
1278
1269
// no way of knowing.
1279
- let mut where_predicates = Vec :: new ( ) ;
1270
+ let mut where_predicates = ThinVec :: new ( ) ;
1280
1271
for mut pred in generics. where_predicates {
1281
1272
if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1282
1273
&& let Some ( GenericParamDef {
@@ -1306,7 +1297,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1306
1297
bounds,
1307
1298
)
1308
1299
} else {
1309
- TyAssocTypeItem ( Box :: new ( generics) , bounds)
1300
+ TyAssocTypeItem ( generics, bounds)
1310
1301
}
1311
1302
} else {
1312
1303
// FIXME: when could this happen? Associated items in inherent impls?
@@ -1317,7 +1308,10 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1317
1308
cx,
1318
1309
Some ( assoc_item. def_id ) ,
1319
1310
) ,
1320
- generics : Generics { params : Vec :: new ( ) , where_predicates : Vec :: new ( ) } ,
1311
+ generics : Generics {
1312
+ params : ThinVec :: new ( ) ,
1313
+ where_predicates : ThinVec :: new ( ) ,
1314
+ } ,
1321
1315
item_type : None ,
1322
1316
} ) ,
1323
1317
Vec :: new ( ) ,
0 commit comments