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