@@ -1297,22 +1297,24 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12971297 hir:: TraitItemKind :: Type ( bounds, Some ( default) ) => {
12981298 let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
12991299 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1300- let item_type =
1300+ let type_from_middle =
13011301 clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , default) ) , cx, None , None ) ;
1302- ItemKind :: AssocTy (
1303- Box :: new ( TypeAlias {
1304- type_ : clean_ty ( default, cx) ,
1305- generics,
1306- inner_type : None ,
1307- item_type : Some ( item_type) ,
1308- } ) ,
1302+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1303+ generics,
13091304 bounds,
1310- )
1305+ type_ : Some ( clean_ty ( default, cx) ) ,
1306+ type_guaranteed_to_come_from_middle : Some ( type_from_middle) ,
1307+ } ) )
13111308 }
13121309 hir:: TraitItemKind :: Type ( bounds, None ) => {
13131310 let generics = enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ;
13141311 let bounds = bounds. iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ;
1315- ItemKind :: RequiredAssocTy ( generics, bounds)
1312+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1313+ generics,
1314+ bounds,
1315+ type_ : None ,
1316+ type_guaranteed_to_come_from_middle : None ,
1317+ } ) )
13161318 }
13171319 } ;
13181320 Item :: from_def_id_and_parts ( local_did, Some ( trait_item. ident . name ) , inner, cx. tcx )
@@ -1342,17 +1344,14 @@ pub(crate) fn clean_impl_item<'tcx>(
13421344 hir:: ImplItemKind :: Type ( hir_ty) => {
13431345 let type_ = clean_ty ( hir_ty, cx) ;
13441346 let generics = clean_generics ( impl_. generics , cx) ;
1345- let item_type =
1347+ let type_from_middle =
13461348 clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , hir_ty) ) , cx, None , None ) ;
1347- ItemKind :: AssocTy (
1348- Box :: new ( TypeAlias {
1349- type_,
1350- generics,
1351- inner_type : None ,
1352- item_type : Some ( item_type) ,
1353- } ) ,
1354- Vec :: new ( ) ,
1355- )
1349+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1350+ generics,
1351+ bounds : Vec :: new ( ) ,
1352+ type_ : Some ( type_) ,
1353+ type_guaranteed_to_come_from_middle : Some ( type_from_middle) ,
1354+ } ) )
13561355 }
13571356 } ;
13581357
@@ -1462,7 +1461,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14621461 ) ;
14631462 simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
14641463
1465- if let ty:: AssocContainer :: Trait = assoc_item. container {
1464+ let ( bounds , type_ ) = if let ty:: AssocContainer :: Trait = assoc_item. container {
14661465 // Move bounds that are (likely) directly attached to the associated type
14671466 // from the where-clause to the associated type.
14681467 // There is no guarantee that this is what the user actually wrote but we have
@@ -1530,50 +1529,27 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
15301529 None => bounds. push ( GenericBound :: maybe_sized ( cx) ) ,
15311530 }
15321531
1533- if tcx. defaultness ( assoc_item. def_id ) . has_value ( ) {
1534- ItemKind :: AssocTy (
1535- Box :: new ( TypeAlias {
1536- type_ : clean_middle_ty (
1537- ty:: Binder :: dummy (
1538- tcx. type_of ( assoc_item. def_id )
1539- . instantiate_identity ( )
1540- . skip_norm_wip ( ) ,
1541- ) ,
1542- cx,
1543- Some ( assoc_item. def_id ) ,
1544- None ,
1545- ) ,
1546- generics,
1547- inner_type : None ,
1548- item_type : None ,
1549- } ) ,
1550- bounds,
1551- )
1552- } else {
1553- ItemKind :: RequiredAssocTy ( generics, bounds)
1554- }
1532+ let type_ = tcx. defaultness ( assoc_item. def_id ) . has_value ( ) . then ( || {
1533+ let ty = tcx. type_of ( assoc_item. def_id ) . instantiate_identity ( ) . skip_norm_wip ( ) ;
1534+ clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, Some ( assoc_item. def_id ) , None )
1535+ } ) ;
1536+
1537+ ( bounds, type_)
15551538 } else {
1556- ItemKind :: AssocTy (
1557- Box :: new ( TypeAlias {
1558- type_ : clean_middle_ty (
1559- ty:: Binder :: dummy (
1560- tcx. type_of ( assoc_item. def_id )
1561- . instantiate_identity ( )
1562- . skip_norm_wip ( ) ,
1563- ) ,
1564- cx,
1565- Some ( assoc_item. def_id ) ,
1566- None ,
1567- ) ,
1568- generics,
1569- inner_type : None ,
1570- item_type : None ,
1571- } ) ,
1572- // Associated types inside trait or inherent impls are not allowed to have
1573- // item bounds. Thus we don't attempt to move any bounds there.
1574- Vec :: new ( ) ,
1575- )
1576- }
1539+ // Associated types inside trait or inherent impls are not allowed to have
1540+ // item bounds. Thus we don't attempt to move any bounds there.
1541+ let bounds = Vec :: new ( ) ;
1542+ let ty = tcx. type_of ( assoc_item. def_id ) . instantiate_identity ( ) . skip_norm_wip ( ) ;
1543+ let type_ =
1544+ clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, Some ( assoc_item. def_id ) , None ) ;
1545+ ( bounds, Some ( type_) )
1546+ } ;
1547+ ItemKind :: AssocTy ( Box :: new ( AssocTy {
1548+ generics,
1549+ bounds,
1550+ type_,
1551+ type_guaranteed_to_come_from_middle : None ,
1552+ } ) )
15771553 }
15781554 } ;
15791555
@@ -2893,10 +2869,10 @@ fn clean_maybe_renamed_item<'tcx>(
28932869 } ) ) ,
28942870 hir:: ItemKind :: TyAlias ( _, generics, ty) => {
28952871 * cx. current_type_aliases . entry ( def_id) . or_insert ( 0 ) += 1 ;
2896- let rustdoc_ty = clean_ty ( ty, cx) ;
2897- let type_ =
2898- clean_middle_ty ( ty:: Binder :: dummy ( lower_ty ( cx. tcx , ty) ) , cx, None , None ) ;
2872+
28992873 let generics = clean_generics ( generics, cx) ;
2874+ let type_ = clean_ty ( ty, cx) ;
2875+
29002876 if let Some ( count) = cx. current_type_aliases . get_mut ( & def_id) {
29012877 * count -= 1 ;
29022878 if * count == 0 {
@@ -2905,18 +2881,12 @@ fn clean_maybe_renamed_item<'tcx>(
29052881 }
29062882
29072883 let ty = cx. tcx . type_of ( def_id) . instantiate_identity ( ) . skip_norm_wip ( ) ;
2908-
29092884 let mut ret = Vec :: new ( ) ;
29102885 let inner_type = clean_ty_alias_inner_type ( ty, cx, & mut ret) ;
29112886
29122887 ret. push ( generate_item_with_correct_attrs (
29132888 cx,
2914- ItemKind :: TyAlias ( Box :: new ( TypeAlias {
2915- generics,
2916- inner_type,
2917- type_ : rustdoc_ty,
2918- item_type : Some ( type_) ,
2919- } ) ) ,
2889+ ItemKind :: TyAlias ( Box :: new ( TypeAlias { generics, inner_type, type_ } ) ) ,
29202890 item. owner_id . def_id . to_def_id ( ) ,
29212891 name,
29222892 import_ids,
0 commit comments