@@ -1360,21 +1360,53 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13601360 }
13611361 }
13621362
1363+ let mut predicates = tcx. explicit_predicates_of ( assoc_item. def_id ) . predicates ;
13631364 if let ty:: TraitContainer = assoc_item. container {
13641365 let bounds = tcx
13651366 . explicit_item_bounds ( assoc_item. def_id )
13661367 . subst_identity_iter_copied ( )
13671368 . 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.
13781410 let mut bounds: Vec < GenericBound > = Vec :: new ( ) ;
13791411 generics. where_predicates . retain_mut ( |pred| match * pred {
13801412 WherePredicate :: BoundPredicate {
@@ -1431,33 +1463,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14311463 }
14321464 None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
14331465 }
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;
14611466
14621467 if tcx. defaultness ( assoc_item. def_id ) . has_value ( ) {
14631468 AssocTypeItem (
@@ -1469,7 +1474,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14691474 None ,
14701475 ) ,
14711476 generics,
1472- // FIXME: should we obtain the Type from HIR and pass it on here?
14731477 item_type : None ,
14741478 } ) ,
14751479 bounds,
@@ -1478,7 +1482,6 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14781482 TyAssocTypeItem ( generics, bounds)
14791483 }
14801484 } else {
1481- // FIXME: when could this happen? Associated items in inherent impls?
14821485 AssocTypeItem (
14831486 Box :: new ( Typedef {
14841487 type_ : clean_middle_ty (
@@ -1487,12 +1490,11 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14871490 Some ( assoc_item. def_id ) ,
14881491 None ,
14891492 ) ,
1490- generics : Generics {
1491- params : ThinVec :: new ( ) ,
1492- where_predicates : ThinVec :: new ( ) ,
1493- } ,
1493+ generics,
14941494 item_type : None ,
14951495 } ) ,
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.
14961498 Vec :: new ( ) ,
14971499 )
14981500 }
0 commit comments