@@ -441,7 +441,7 @@ fn clean_projection<'tcx>(
441
441
assoc : projection_to_path_segment ( ty, cx) ,
442
442
should_show_cast,
443
443
self_type,
444
- trait_,
444
+ trait_ : Some ( trait_ ) ,
445
445
} ) )
446
446
}
447
447
@@ -1330,7 +1330,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
1330
1330
let mut bounds: Vec < GenericBound > = Vec :: new ( ) ;
1331
1331
generics. where_predicates . retain_mut ( |pred| match * pred {
1332
1332
WherePredicate :: BoundPredicate {
1333
- ty : QPath ( box QPathData { ref assoc, ref self_type, ref trait_, .. } ) ,
1333
+ ty :
1334
+ QPath ( box QPathData {
1335
+ ref assoc,
1336
+ ref self_type,
1337
+ trait_ : Some ( ref trait_) ,
1338
+ ..
1339
+ } ) ,
1334
1340
bounds : ref mut pred_bounds,
1335
1341
..
1336
1342
} => {
@@ -1492,25 +1498,30 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
1492
1498
assoc : clean_path_segment ( p. segments . last ( ) . expect ( "segments were empty" ) , cx) ,
1493
1499
should_show_cast,
1494
1500
self_type,
1495
- trait_,
1501
+ trait_ : Some ( trait_ ) ,
1496
1502
} ) )
1497
1503
}
1498
1504
hir:: QPath :: TypeRelative ( qself, segment) => {
1499
1505
let ty = hir_ty_to_ty ( cx. tcx , hir_ty) ;
1500
- let res = match ty. kind ( ) {
1506
+ let self_type = clean_ty ( qself, cx) ;
1507
+
1508
+ let ( trait_, should_show_cast) = match ty. kind ( ) {
1501
1509
ty:: Alias ( ty:: Projection , proj) => {
1502
- Res :: Def ( DefKind :: Trait , proj. trait_ref ( cx. tcx ) . def_id )
1510
+ let res = Res :: Def ( DefKind :: Trait , proj. trait_ref ( cx. tcx ) . def_id ) ;
1511
+ let trait_ = clean_path ( & hir:: Path { span, res, segments : & [ ] } , cx) ;
1512
+ register_res ( cx, trait_. res ) ;
1513
+ let self_def_id = res. opt_def_id ( ) ;
1514
+ let should_show_cast =
1515
+ compute_should_show_cast ( self_def_id, & trait_, & self_type) ;
1516
+
1517
+ ( Some ( trait_) , should_show_cast)
1503
1518
}
1519
+ ty:: Alias ( ty:: Inherent , _) => ( None , false ) ,
1504
1520
// Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s.
1505
1521
ty:: Error ( _) => return Type :: Infer ,
1506
- // Otherwise, this is an inherent associated type.
1507
- _ => return clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, None ) ,
1522
+ _ => bug ! ( "clean: expected associated type, found `{ty:?}`" ) ,
1508
1523
} ;
1509
- let trait_ = clean_path ( & hir:: Path { span, res, segments : & [ ] } , cx) ;
1510
- register_res ( cx, trait_. res ) ;
1511
- let self_def_id = res. opt_def_id ( ) ;
1512
- let self_type = clean_ty ( qself, cx) ;
1513
- let should_show_cast = compute_should_show_cast ( self_def_id, & trait_, & self_type) ;
1524
+
1514
1525
Type :: QPath ( Box :: new ( QPathData {
1515
1526
assoc : clean_path_segment ( segment, cx) ,
1516
1527
should_show_cast,
@@ -1836,9 +1847,28 @@ pub(crate) fn clean_middle_ty<'tcx>(
1836
1847
clean_projection ( bound_ty. rebind ( * data) , cx, parent_def_id)
1837
1848
}
1838
1849
1839
- // FIXME(fmease): Clean inherent projections properly. This requires making the trait ref in
1840
- // `QPathData` optional or alternatively adding a new `clean::Type` variant.
1841
- ty:: Alias ( ty:: Inherent , _data) => Type :: Infer ,
1850
+ ty:: Alias ( ty:: Inherent , alias_ty) => {
1851
+ let alias_ty = bound_ty. rebind ( alias_ty) ;
1852
+ let self_type = clean_middle_ty ( alias_ty. map_bound ( |ty| ty. self_ty ( ) ) , cx, None ) ;
1853
+
1854
+ Type :: QPath ( Box :: new ( QPathData {
1855
+ assoc : PathSegment {
1856
+ name : cx. tcx . associated_item ( alias_ty. skip_binder ( ) . def_id ) . name ,
1857
+ args : GenericArgs :: AngleBracketed {
1858
+ args : substs_to_args (
1859
+ cx,
1860
+ alias_ty. map_bound ( |ty| ty. substs . as_slice ( ) ) ,
1861
+ true ,
1862
+ )
1863
+ . into ( ) ,
1864
+ bindings : Default :: default ( ) ,
1865
+ } ,
1866
+ } ,
1867
+ should_show_cast : false ,
1868
+ self_type,
1869
+ trait_ : None ,
1870
+ } ) )
1871
+ }
1842
1872
1843
1873
ty:: Param ( ref p) => {
1844
1874
if let Some ( bounds) = cx. impl_trait_bounds . remove ( & p. index . into ( ) ) {
0 commit comments