@@ -371,10 +371,9 @@ fn clean_where_predicate<'tcx>(
371
371
bounds : wrp. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
372
372
} ,
373
373
374
- hir:: WherePredicateKind :: EqPredicate ( wrp) => WherePredicate :: EqPredicate {
375
- lhs : clean_ty ( wrp. lhs_ty , cx) ,
376
- rhs : clean_ty ( wrp. rhs_ty , cx) . into ( ) ,
377
- } ,
374
+ // We should never actually reach this case because these predicates should've already been
375
+ // rejected in an earlier compiler pass. This feature isn't fully implemented (#20041).
376
+ hir:: WherePredicateKind :: EqPredicate ( _) => bug ! ( "EqPredicate" ) ,
378
377
} )
379
378
}
380
379
@@ -470,68 +469,55 @@ fn clean_projection_predicate<'tcx>(
470
469
cx : & mut DocContext < ' tcx > ,
471
470
) -> WherePredicate {
472
471
WherePredicate :: EqPredicate {
473
- lhs : clean_projection (
474
- pred. map_bound ( |p| {
475
- // FIXME: This needs to be made resilient for `AliasTerm`s that
476
- // are associated consts.
477
- p. projection_term . expect_ty ( cx. tcx )
478
- } ) ,
479
- cx,
480
- None ,
481
- ) ,
472
+ lhs : clean_projection ( pred. map_bound ( |p| p. projection_term ) , cx, None ) ,
482
473
rhs : clean_middle_term ( pred. map_bound ( |p| p. term ) , cx) ,
483
474
}
484
475
}
485
476
486
477
fn clean_projection < ' tcx > (
487
- ty : ty:: Binder < ' tcx , ty:: AliasTy < ' tcx > > ,
478
+ proj : ty:: Binder < ' tcx , ty:: AliasTerm < ' tcx > > ,
488
479
cx : & mut DocContext < ' tcx > ,
489
- def_id : Option < DefId > ,
490
- ) -> Type {
491
- if cx. tcx . is_impl_trait_in_trait ( ty. skip_binder ( ) . def_id ) {
492
- return clean_middle_opaque_bounds ( cx, ty. skip_binder ( ) . def_id , ty. skip_binder ( ) . args ) ;
493
- }
494
-
480
+ parent_def_id : Option < DefId > ,
481
+ ) -> QPathData {
495
482
let trait_ = clean_trait_ref_with_constraints (
496
483
cx,
497
- ty . map_bound ( |ty| ty . trait_ref ( cx. tcx ) ) ,
484
+ proj . map_bound ( |proj| proj . trait_ref ( cx. tcx ) ) ,
498
485
ThinVec :: new ( ) ,
499
486
) ;
500
- let self_type = clean_middle_ty ( ty. map_bound ( |ty| ty. self_ty ( ) ) , cx, None , None ) ;
501
- let self_def_id = if let Some ( def_id) = def_id {
502
- cx. tcx . opt_parent ( def_id) . or ( Some ( def_id) )
503
- } else {
504
- self_type. def_id ( & cx. cache )
487
+ let self_type = clean_middle_ty ( proj. map_bound ( |proj| proj. self_ty ( ) ) , cx, None , None ) ;
488
+ let self_def_id = match parent_def_id {
489
+ Some ( parent_def_id) => cx. tcx . opt_parent ( parent_def_id) . or ( Some ( parent_def_id) ) ,
490
+ None => self_type. def_id ( & cx. cache ) ,
505
491
} ;
506
- let should_show_cast = compute_should_show_cast ( self_def_id, & trait_, & self_type) ;
507
- Type :: QPath ( Box :: new ( QPathData {
508
- assoc : projection_to_path_segment ( ty , cx ) ,
509
- should_show_cast ,
492
+ let should_fully_qualify = should_fully_qualify_path ( self_def_id, & trait_, & self_type) ;
493
+
494
+ QPathData {
495
+ assoc : projection_to_path_segment ( proj , cx ) ,
510
496
self_type,
497
+ should_fully_qualify,
511
498
trait_ : Some ( trait_) ,
512
- } ) )
499
+ }
513
500
}
514
501
515
- fn compute_should_show_cast ( self_def_id : Option < DefId > , trait_ : & Path , self_type : & Type ) -> bool {
502
+ fn should_fully_qualify_path ( self_def_id : Option < DefId > , trait_ : & Path , self_type : & Type ) -> bool {
516
503
!trait_. segments . is_empty ( )
517
504
&& self_def_id
518
505
. zip ( Some ( trait_. def_id ( ) ) )
519
506
. map_or ( !self_type. is_self_type ( ) , |( id, trait_) | id != trait_)
520
507
}
521
508
522
509
fn projection_to_path_segment < ' tcx > (
523
- ty : ty:: Binder < ' tcx , ty:: AliasTy < ' tcx > > ,
510
+ proj : ty:: Binder < ' tcx , ty:: AliasTerm < ' tcx > > ,
524
511
cx : & mut DocContext < ' tcx > ,
525
512
) -> PathSegment {
526
- let def_id = ty. skip_binder ( ) . def_id ;
527
- let item = cx. tcx . associated_item ( def_id) ;
513
+ let def_id = proj. skip_binder ( ) . def_id ;
528
514
let generics = cx. tcx . generics_of ( def_id) ;
529
515
PathSegment {
530
- name : item . name ( ) ,
516
+ name : cx . tcx . item_name ( def_id ) ,
531
517
args : GenericArgs :: AngleBracketed {
532
518
args : clean_middle_generic_args (
533
519
cx,
534
- ty . map_bound ( |ty| & ty. args [ generics. parent_count ..] ) ,
520
+ proj . map_bound ( |ty| & ty. args [ generics. parent_count ..] ) ,
535
521
false ,
536
522
def_id,
537
523
) ,
@@ -845,7 +831,7 @@ fn clean_ty_generics<'tcx>(
845
831
. predicates
846
832
. iter ( )
847
833
. flat_map ( |( pred, _) | {
848
- let mut projection = None ;
834
+ let mut proj_pred = None ;
849
835
let param_idx = {
850
836
let bound_p = pred. kind ( ) ;
851
837
match bound_p. skip_binder ( ) {
@@ -860,7 +846,7 @@ fn clean_ty_generics<'tcx>(
860
846
ty:: ClauseKind :: Projection ( p)
861
847
if let ty:: Param ( param) = p. projection_term . self_ty ( ) . kind ( ) =>
862
848
{
863
- projection = Some ( bound_p. rebind ( p) ) ;
849
+ proj_pred = Some ( bound_p. rebind ( p) ) ;
864
850
Some ( param. index )
865
851
}
866
852
_ => None ,
@@ -874,22 +860,12 @@ fn clean_ty_generics<'tcx>(
874
860
875
861
bounds. extend ( pred. get_bounds ( ) . into_iter ( ) . flatten ( ) . cloned ( ) ) ;
876
862
877
- if let Some ( proj) = projection
878
- && let lhs = clean_projection (
879
- proj. map_bound ( |p| {
880
- // FIXME: This needs to be made resilient for `AliasTerm`s that
881
- // are associated consts.
882
- p. projection_term . expect_ty ( cx. tcx )
883
- } ) ,
884
- cx,
885
- None ,
886
- )
887
- && let Some ( ( _, trait_did, name) ) = lhs. projection ( )
888
- {
863
+ if let Some ( pred) = proj_pred {
864
+ let lhs = clean_projection ( pred. map_bound ( |p| p. projection_term ) , cx, None ) ;
889
865
impl_trait_proj. entry ( param_idx) . or_default ( ) . push ( (
890
- trait_did ,
891
- name ,
892
- proj . map_bound ( |p| p. term ) ,
866
+ lhs . trait_ . unwrap ( ) . def_id ( ) ,
867
+ lhs . assoc ,
868
+ pred . map_bound ( |p| p. term ) ,
893
869
) ) ;
894
870
}
895
871
@@ -1695,10 +1671,11 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
1695
1671
register_res ( cx, trait_. res ) ;
1696
1672
let self_def_id = DefId :: local ( qself. hir_id . owner . def_id . local_def_index ) ;
1697
1673
let self_type = clean_ty ( qself, cx) ;
1698
- let should_show_cast = compute_should_show_cast ( Some ( self_def_id) , & trait_, & self_type) ;
1674
+ let should_fully_qualify =
1675
+ should_fully_qualify_path ( Some ( self_def_id) , & trait_, & self_type) ;
1699
1676
Type :: QPath ( Box :: new ( QPathData {
1700
1677
assoc : clean_path_segment ( p. segments . last ( ) . expect ( "segments were empty" ) , cx) ,
1701
- should_show_cast ,
1678
+ should_fully_qualify ,
1702
1679
self_type,
1703
1680
trait_ : Some ( trait_) ,
1704
1681
} ) )
@@ -1707,16 +1684,16 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
1707
1684
let ty = lower_ty ( cx. tcx , hir_ty) ;
1708
1685
let self_type = clean_ty ( qself, cx) ;
1709
1686
1710
- let ( trait_, should_show_cast ) = match ty. kind ( ) {
1687
+ let ( trait_, should_fully_qualify ) = match ty. kind ( ) {
1711
1688
ty:: Alias ( ty:: Projection , proj) => {
1712
1689
let res = Res :: Def ( DefKind :: Trait , proj. trait_ref ( cx. tcx ) . def_id ) ;
1713
1690
let trait_ = clean_path ( & hir:: Path { span, res, segments : & [ ] } , cx) ;
1714
1691
register_res ( cx, trait_. res ) ;
1715
1692
let self_def_id = res. opt_def_id ( ) ;
1716
- let should_show_cast =
1717
- compute_should_show_cast ( self_def_id, & trait_, & self_type) ;
1693
+ let should_fully_qualify =
1694
+ should_fully_qualify_path ( self_def_id, & trait_, & self_type) ;
1718
1695
1719
- ( Some ( trait_) , should_show_cast )
1696
+ ( Some ( trait_) , should_fully_qualify )
1720
1697
}
1721
1698
ty:: Alias ( ty:: Inherent , _) => ( None , false ) ,
1722
1699
// Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s.
@@ -1726,7 +1703,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
1726
1703
1727
1704
Type :: QPath ( Box :: new ( QPathData {
1728
1705
assoc : clean_path_segment ( segment, cx) ,
1729
- should_show_cast ,
1706
+ should_fully_qualify ,
1730
1707
self_type,
1731
1708
trait_,
1732
1709
} ) )
@@ -2145,14 +2122,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
2145
2122
. map ( |pb| AssocItemConstraint {
2146
2123
assoc : projection_to_path_segment (
2147
2124
pb. map_bound ( |pb| {
2148
- pb
2149
- // HACK(compiler-errors): Doesn't actually matter what self
2150
- // type we put here, because we're only using the GAT's args.
2151
- . with_self_ty ( cx. tcx , cx. tcx . types . self_param )
2125
+ pb. with_self_ty ( cx. tcx , cx. tcx . types . trait_object_dummy_self )
2152
2126
. projection_term
2153
- // FIXME: This needs to be made resilient for `AliasTerm`s
2154
- // that are associated consts.
2155
- . expect_ty ( cx. tcx )
2156
2127
} ) ,
2157
2128
cx,
2158
2129
) ,
@@ -2185,18 +2156,25 @@ pub(crate) fn clean_middle_ty<'tcx>(
2185
2156
Tuple ( t. iter ( ) . map ( |t| clean_middle_ty ( bound_ty. rebind ( t) , cx, None , None ) ) . collect ( ) )
2186
2157
}
2187
2158
2188
- ty:: Alias ( ty:: Projection , data) => {
2189
- clean_projection ( bound_ty. rebind ( data) , cx, parent_def_id)
2159
+ ty:: Alias ( ty:: Projection , alias_ty @ ty:: AliasTy { def_id, args, .. } ) => {
2160
+ if cx. tcx . is_impl_trait_in_trait ( def_id) {
2161
+ clean_middle_opaque_bounds ( cx, def_id, args)
2162
+ } else {
2163
+ Type :: QPath ( Box :: new ( clean_projection (
2164
+ bound_ty. rebind ( alias_ty. into ( ) ) ,
2165
+ cx,
2166
+ parent_def_id,
2167
+ ) ) )
2168
+ }
2190
2169
}
2191
2170
2192
- ty:: Alias ( ty:: Inherent , alias_ty) => {
2193
- let def_id = alias_ty. def_id ;
2171
+ ty:: Alias ( ty:: Inherent , alias_ty @ ty:: AliasTy { def_id, .. } ) => {
2194
2172
let alias_ty = bound_ty. rebind ( alias_ty) ;
2195
2173
let self_type = clean_middle_ty ( alias_ty. map_bound ( |ty| ty. self_ty ( ) ) , cx, None , None ) ;
2196
2174
2197
2175
Type :: QPath ( Box :: new ( QPathData {
2198
2176
assoc : PathSegment {
2199
- name : cx. tcx . associated_item ( def_id) . name ( ) ,
2177
+ name : cx. tcx . item_name ( def_id) ,
2200
2178
args : GenericArgs :: AngleBracketed {
2201
2179
args : clean_middle_generic_args (
2202
2180
cx,
@@ -2207,26 +2185,21 @@ pub(crate) fn clean_middle_ty<'tcx>(
2207
2185
constraints : Default :: default ( ) ,
2208
2186
} ,
2209
2187
} ,
2210
- should_show_cast : false ,
2188
+ should_fully_qualify : false ,
2211
2189
self_type,
2212
2190
trait_ : None ,
2213
2191
} ) )
2214
2192
}
2215
2193
2216
- ty:: Alias ( ty:: Free , data ) => {
2194
+ ty:: Alias ( ty:: Free , ty :: AliasTy { def_id , args , .. } ) => {
2217
2195
if cx. tcx . features ( ) . lazy_type_alias ( ) {
2218
2196
// Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
2219
2197
// we need to use `type_of`.
2220
- let path = clean_middle_path (
2221
- cx,
2222
- data. def_id ,
2223
- false ,
2224
- ThinVec :: new ( ) ,
2225
- bound_ty. rebind ( data. args ) ,
2226
- ) ;
2198
+ let path =
2199
+ clean_middle_path ( cx, def_id, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
2227
2200
Type :: Path { path }
2228
2201
} else {
2229
- let ty = cx. tcx . type_of ( data . def_id ) . instantiate ( cx. tcx , data . args ) ;
2202
+ let ty = cx. tcx . type_of ( def_id) . instantiate ( cx. tcx , args) ;
2230
2203
clean_middle_ty ( bound_ty. rebind ( ty) , cx, None , None )
2231
2204
}
2232
2205
}
@@ -2313,18 +2286,17 @@ fn clean_middle_opaque_bounds<'tcx>(
2313
2286
let bindings: ThinVec < _ > = bounds
2314
2287
. iter ( )
2315
2288
. filter_map ( |( bound, _) | {
2316
- if let ty:: ClauseKind :: Projection ( proj) = bound. kind ( ) . skip_binder ( )
2317
- && proj. projection_term . trait_ref ( cx. tcx ) == trait_ref. skip_binder ( )
2289
+ let bound = bound. kind ( ) ;
2290
+ if let ty:: ClauseKind :: Projection ( proj_pred) = bound. skip_binder ( )
2291
+ && proj_pred. projection_term . trait_ref ( cx. tcx ) == trait_ref. skip_binder ( )
2318
2292
{
2319
2293
return Some ( AssocItemConstraint {
2320
2294
assoc : projection_to_path_segment (
2321
- // FIXME: This needs to be made resilient for `AliasTerm`s that
2322
- // are associated consts.
2323
- bound. kind ( ) . rebind ( proj. projection_term . expect_ty ( cx. tcx ) ) ,
2295
+ bound. rebind ( proj_pred. projection_term ) ,
2324
2296
cx,
2325
2297
) ,
2326
2298
kind : AssocItemConstraintKind :: Equality {
2327
- term : clean_middle_term ( bound. kind ( ) . rebind ( proj . term ) , cx) ,
2299
+ term : clean_middle_term ( bound. rebind ( proj_pred . term ) , cx) ,
2328
2300
} ,
2329
2301
} ) ;
2330
2302
}
0 commit comments