@@ -1352,21 +1352,53 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1352
1352
}
1353
1353
}
1354
1354
1355
+ let mut predicates = tcx. explicit_predicates_of ( assoc_item. def_id ) . predicates ;
1355
1356
if let ty:: TraitContainer = assoc_item. container {
1356
1357
let bounds = tcx
1357
1358
. explicit_item_bounds ( assoc_item. def_id )
1358
1359
. subst_identity_iter_copied ( )
1359
1360
. map ( |( c, s) | ( c. as_predicate ( ) , s) ) ;
1360
- let predicates = tcx. explicit_predicates_of ( assoc_item. def_id ) . predicates ;
1361
- let predicates =
1362
- tcx. arena . alloc_from_iter ( bounds. chain ( predicates. iter ( ) . copied ( ) ) ) ;
1363
- let mut generics = clean_ty_generics (
1364
- cx,
1365
- tcx. generics_of ( assoc_item. def_id ) ,
1366
- ty:: GenericPredicates { parent : None , predicates } ,
1367
- ) ;
1368
- // Filter out the bounds that are (likely?) directly attached to the associated type,
1369
- // as opposed to being located in the where clause.
1361
+ predicates = tcx. arena . alloc_from_iter ( bounds. chain ( predicates. iter ( ) . copied ( ) ) ) ;
1362
+ }
1363
+ let mut generics = clean_ty_generics (
1364
+ cx,
1365
+ tcx. generics_of ( assoc_item. def_id ) ,
1366
+ ty:: GenericPredicates { parent : None , predicates } ,
1367
+ ) ;
1368
+ // Move bounds that are (likely) directly attached to the parameters of the
1369
+ // (generic) associated type from the where clause to the respective parameter.
1370
+ // There is no guarantee that this is what the user actually wrote but we have
1371
+ // no way of knowing.
1372
+ let mut where_predicates = ThinVec :: new ( ) ;
1373
+ for mut pred in generics. where_predicates {
1374
+ if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1375
+ && let Some ( GenericParamDef {
1376
+ kind : GenericParamDefKind :: Type { bounds : param_bounds, .. } ,
1377
+ ..
1378
+ } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1379
+ {
1380
+ param_bounds. append ( bounds) ;
1381
+ } else if let WherePredicate :: RegionPredicate { lifetime : Lifetime ( arg) , bounds } = & mut pred
1382
+ && let Some ( GenericParamDef {
1383
+ kind : GenericParamDefKind :: Lifetime { outlives : param_bounds } ,
1384
+ ..
1385
+ } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1386
+ {
1387
+ param_bounds. extend ( bounds. drain ( ..) . map ( |bound| match bound {
1388
+ GenericBound :: Outlives ( lifetime) => lifetime,
1389
+ _ => unreachable ! ( ) ,
1390
+ } ) ) ;
1391
+ } else {
1392
+ where_predicates. push ( pred) ;
1393
+ }
1394
+ }
1395
+ generics. where_predicates = where_predicates;
1396
+
1397
+ if let ty:: TraitContainer = assoc_item. container {
1398
+ // Move bounds that are (likely) directly attached to the associated type
1399
+ // from the where-clause to the associated type.
1400
+ // There is no guarantee that this is what the user actually wrote but we have
1401
+ // no way of knowing.
1370
1402
let mut bounds: Vec < GenericBound > = Vec :: new ( ) ;
1371
1403
generics. where_predicates . retain_mut ( |pred| match * pred {
1372
1404
WherePredicate :: BoundPredicate {
@@ -1423,33 +1455,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1423
1455
}
1424
1456
None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
1425
1457
}
1426
- // Move bounds that are (likely) directly attached to the parameters of the
1427
- // (generic) associated type from the where clause to the respective parameter.
1428
- // There is no guarantee that this is what the user actually wrote but we have
1429
- // no way of knowing.
1430
- let mut where_predicates = ThinVec :: new ( ) ;
1431
- for mut pred in generics. where_predicates {
1432
- if let WherePredicate :: BoundPredicate { ty : Generic ( arg) , bounds, .. } = & mut pred
1433
- && let Some ( GenericParamDef {
1434
- kind : GenericParamDefKind :: Type { bounds : param_bounds, .. } ,
1435
- ..
1436
- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg)
1437
- {
1438
- param_bounds. append ( bounds) ;
1439
- } else if let WherePredicate :: RegionPredicate { lifetime : Lifetime ( arg) , bounds } = & mut pred
1440
- && let Some ( GenericParamDef {
1441
- kind : GenericParamDefKind :: Lifetime { outlives : param_bounds } ,
1442
- ..
1443
- } ) = generics. params . iter_mut ( ) . find ( |param| & param. name == arg) {
1444
- param_bounds. extend ( bounds. drain ( ..) . map ( |bound| match bound {
1445
- GenericBound :: Outlives ( lifetime) => lifetime,
1446
- _ => unreachable ! ( ) ,
1447
- } ) ) ;
1448
- } else {
1449
- where_predicates. push ( pred) ;
1450
- }
1451
- }
1452
- generics. where_predicates = where_predicates;
1453
1458
1454
1459
if tcx. defaultness ( assoc_item. def_id ) . has_value ( ) {
1455
1460
AssocTypeItem (
@@ -1461,7 +1466,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1461
1466
None ,
1462
1467
) ,
1463
1468
generics,
1464
- // FIXME: should we obtain the Type from HIR and pass it on here?
1465
1469
item_type : None ,
1466
1470
} ) ,
1467
1471
bounds,
@@ -1470,7 +1474,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1470
1474
TyAssocTypeItem ( generics, bounds)
1471
1475
}
1472
1476
} else {
1473
- // FIXME: when could this happen? Associated items in inherent impls?
1474
1477
AssocTypeItem (
1475
1478
Box :: new ( Typedef {
1476
1479
type_ : clean_middle_ty (
@@ -1479,12 +1482,11 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1479
1482
Some ( assoc_item. def_id ) ,
1480
1483
None ,
1481
1484
) ,
1482
- generics : Generics {
1483
- params : ThinVec :: new ( ) ,
1484
- where_predicates : ThinVec :: new ( ) ,
1485
- } ,
1485
+ generics,
1486
1486
item_type : None ,
1487
1487
} ) ,
1488
+ // Associated types inside trait or inherent impls are not allowed to have
1489
+ // item bounds. Thus we don't attempt to move any bounds there.
1488
1490
Vec :: new ( ) ,
1489
1491
)
1490
1492
}
0 commit comments