@@ -1315,25 +1315,18 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
13151315 clean_function ( cx, sig, trait_item. generics , params, local_did) ;
13161316 ItemKind :: AssocFn ( Box :: new ( AssocFn { generics, decl, body } ) )
13171317 }
1318- hir:: TraitItemKind :: Type ( bounds, Some ( default ) ) => {
1318+ hir:: TraitItemKind :: Type ( bounds, ty ) => {
13191319 let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
13201320 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1321- let item_type =
1322- clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , default) ) , cx, None , None ) ;
1323- ItemKind :: AssocTy (
1324- Box :: new ( TypeAlias {
1325- type_ : clean_ty ( default, cx) ,
1326- generics,
1327- inner_type : None ,
1328- item_type : Some ( item_type) ,
1329- } ) ,
1321+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1322+ generics,
13301323 bounds,
1331- )
1332- }
1333- hir :: TraitItemKind :: Type ( bounds , None ) => {
1334- let generics = enter_impl_trait ( cx , |cx| clean_generics ( trait_item . generics , cx) ) ;
1335- let bounds = bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x , cx ) ) . collect ( ) ;
1336- ItemKind :: RequiredAssocTy ( generics , bounds )
1324+ ty : ty . map ( |ty| {
1325+ let middle_ty = ty :: Binder :: dummy ( lower_ty ( cx . tcx , ty ) ) ;
1326+ let middle_ty = Some ( clean_middle_ty ( middle_ty , cx , None , None ) ) ;
1327+ AliasedTy { ty : clean_ty ( ty , cx) , middle_ty }
1328+ } ) ,
1329+ } ) )
13371330 }
13381331 } ;
13391332 Item :: from_def_id_and_parts ( local_did, Some ( trait_item. ident . name ) , inner, cx. tcx )
@@ -1364,20 +1357,16 @@ pub(crate) fn clean_impl_item<'tcx>(
13641357 } ) ) ,
13651358 } ) )
13661359 }
1367- hir:: ImplItemKind :: Type ( hir_ty) => {
1368- let type_ = clean_ty ( hir_ty, cx) ;
1360+ hir:: ImplItemKind :: Type ( ty) => {
13691361 let generics = clean_generics ( impl_. generics , cx) ;
1370- let item_type =
1371- clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , hir_ty) ) , cx, None , None ) ;
1372- ItemKind :: AssocTy (
1373- Box :: new ( TypeAlias {
1374- type_,
1375- generics,
1376- inner_type : None ,
1377- item_type : Some ( item_type) ,
1378- } ) ,
1379- Vec :: new ( ) ,
1380- )
1362+ let middle_ty =
1363+ clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , ty) ) , cx, None , None ) ;
1364+ let ty = clean_ty ( ty, cx) ;
1365+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1366+ generics,
1367+ bounds : Vec :: new ( ) ,
1368+ ty : Some ( AliasedTy { ty, middle_ty : Some ( middle_ty) } ) ,
1369+ } ) )
13811370 }
13821371 } ;
13831372
@@ -1487,7 +1476,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14871476 ) ;
14881477 simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
14891478
1490- if let ty:: AssocContainer :: Trait = assoc_item. container {
1479+ let ( bounds , ty ) = if let ty:: AssocContainer :: Trait = assoc_item. container {
14911480 // Move bounds that are (likely) directly attached to the associated type
14921481 // from the where-clause to the associated type.
14931482 // There is no guarantee that this is what the user actually wrote but we have
@@ -1555,50 +1544,24 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
15551544 None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
15561545 }
15571546
1558- if tcx. defaultness ( assoc_item. def_id ) . has_value ( ) {
1559- ItemKind :: AssocTy (
1560- Box :: new ( TypeAlias {
1561- type_ : clean_middle_ty (
1562- ty:: Binder :: dummy (
1563- tcx. type_of ( assoc_item. def_id )
1564- . instantiate_identity ( )
1565- . skip_norm_wip ( ) ,
1566- ) ,
1567- cx,
1568- Some ( assoc_item. def_id ) ,
1569- None ,
1570- ) ,
1571- generics,
1572- inner_type : None ,
1573- item_type : None ,
1574- } ) ,
1575- bounds,
1576- )
1577- } else {
1578- ItemKind :: RequiredAssocTy ( generics, bounds)
1579- }
1547+ let ty = tcx. defaultness ( assoc_item. def_id ) . has_value ( ) . then ( || {
1548+ let ty = tcx. type_of ( assoc_item. def_id ) . instantiate_identity ( ) . skip_norm_wip ( ) ;
1549+ clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, Some ( assoc_item. def_id ) , None )
1550+ } ) ;
1551+
1552+ ( bounds, ty)
15801553 } else {
1581- ItemKind :: AssocTy (
1582- Box :: new ( TypeAlias {
1583- type_ : clean_middle_ty (
1584- ty:: Binder :: dummy (
1585- tcx. type_of ( assoc_item. def_id )
1586- . instantiate_identity ( )
1587- . skip_norm_wip ( ) ,
1588- ) ,
1589- cx,
1590- Some ( assoc_item. def_id ) ,
1591- None ,
1592- ) ,
1593- generics,
1594- inner_type : None ,
1595- item_type : None ,
1596- } ) ,
1597- // Associated types inside trait or inherent impls are not allowed to have
1598- // item bounds. Thus we don't attempt to move any bounds there.
1599- Vec :: new ( ) ,
1600- )
1601- }
1554+ let ty = tcx. type_of ( assoc_item. def_id ) . instantiate_identity ( ) . skip_norm_wip ( ) ;
1555+ let ty = clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, Some ( assoc_item. def_id ) , None ) ;
1556+ // Associated types inside trait or inherent impls are not allowed to have
1557+ // item bounds. Thus we don't attempt to move any bounds there.
1558+ ( Vec :: new ( ) , Some ( ty) )
1559+ } ;
1560+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1561+ generics,
1562+ bounds,
1563+ ty : ty. map ( |ty| AliasedTy { ty, middle_ty : None } ) ,
1564+ } ) )
16021565 }
16031566 } ;
16041567
@@ -2948,10 +2911,10 @@ fn clean_maybe_renamed_item<'tcx>(
29482911 } ) ) ,
29492912 hir:: ItemKind :: TyAlias ( _, generics, ty) => {
29502913 * cx. current_type_aliases . entry ( def_id) . or_insert ( 0 ) += 1 ;
2951- let rustdoc_ty = clean_ty ( ty, cx) ;
2952- let type_ =
2953- clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , ty) ) , cx, None , None ) ;
2914+
29542915 let generics = clean_generics ( generics, cx) ;
2916+ let type_ = clean_ty ( ty, cx) ;
2917+
29552918 if let Some ( count) = cx. current_type_aliases . get_mut ( & def_id) {
29562919 * count -= 1 ;
29572920 if * count == 0 {
@@ -2960,18 +2923,12 @@ fn clean_maybe_renamed_item<'tcx>(
29602923 }
29612924
29622925 let ty = cx. tcx . type_of ( def_id) . instantiate_identity ( ) . skip_norm_wip ( ) ;
2963-
29642926 let mut ret = Vec :: new ( ) ;
29652927 let inner_type = clean_ty_alias_inner_type ( ty, cx, & mut ret) ;
29662928
29672929 ret. push ( generate_item_with_correct_attrs (
29682930 cx,
2969- ItemKind :: TyAlias ( Box :: new ( TypeAlias {
2970- generics,
2971- inner_type,
2972- type_ : rustdoc_ty,
2973- item_type : Some ( type_) ,
2974- } ) ) ,
2931+ ItemKind :: TyAlias ( Box :: new ( TyAlias { generics, inner_type, ty : type_ } ) ) ,
29752932 item. owner_id . def_id . to_def_id ( ) ,
29762933 name,
29772934 import_ids,
0 commit comments