@@ -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,46 +469,34 @@ 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
492
let should_fully_qualify = should_fully_qualify_path ( self_def_id, & trait_, & self_type) ;
507
- Type :: QPath ( Box :: new ( QPathData {
508
- assoc : projection_to_path_segment ( ty , cx ) ,
509
- should_fully_qualify ,
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
502
fn should_fully_qualify_path ( self_def_id : Option < DefId > , trait_ : & Path , self_type : & Type ) -> bool {
@@ -520,18 +507,17 @@ fn should_fully_qualify_path(self_def_id: Option<DefId>, trait_: &Path, self_typ
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
@@ -2146,14 +2122,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
2146
2122
. map ( |pb| AssocItemConstraint {
2147
2123
assoc : projection_to_path_segment (
2148
2124
pb. map_bound ( |pb| {
2149
- pb
2150
- // HACK(compiler-errors): Doesn't actually matter what self
2151
- // type we put here, because we're only using the GAT's args.
2152
- . with_self_ty ( cx. tcx , cx. tcx . types . self_param )
2125
+ pb. with_self_ty ( cx. tcx , cx. tcx . types . trait_object_dummy_self )
2153
2126
. projection_term
2154
- // FIXME: This needs to be made resilient for `AliasTerm`s
2155
- // that are associated consts.
2156
- . expect_ty ( cx. tcx )
2157
2127
} ) ,
2158
2128
cx,
2159
2129
) ,
@@ -2186,18 +2156,25 @@ pub(crate) fn clean_middle_ty<'tcx>(
2186
2156
Tuple ( t. iter ( ) . map ( |t| clean_middle_ty ( bound_ty. rebind ( t) , cx, None , None ) ) . collect ( ) )
2187
2157
}
2188
2158
2189
- ty:: Alias ( ty:: Projection , data) => {
2190
- 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
+ }
2191
2169
}
2192
2170
2193
- ty:: Alias ( ty:: Inherent , alias_ty) => {
2194
- let def_id = alias_ty. def_id ;
2171
+ ty:: Alias ( ty:: Inherent , alias_ty @ ty:: AliasTy { def_id, .. } ) => {
2195
2172
let alias_ty = bound_ty. rebind ( alias_ty) ;
2196
2173
let self_type = clean_middle_ty ( alias_ty. map_bound ( |ty| ty. self_ty ( ) ) , cx, None , None ) ;
2197
2174
2198
2175
Type :: QPath ( Box :: new ( QPathData {
2199
2176
assoc : PathSegment {
2200
- name : cx. tcx . associated_item ( def_id) . name ( ) ,
2177
+ name : cx. tcx . item_name ( def_id) ,
2201
2178
args : GenericArgs :: AngleBracketed {
2202
2179
args : clean_middle_generic_args (
2203
2180
cx,
@@ -2214,20 +2191,15 @@ pub(crate) fn clean_middle_ty<'tcx>(
2214
2191
} ) )
2215
2192
}
2216
2193
2217
- ty:: Alias ( ty:: Free , data ) => {
2194
+ ty:: Alias ( ty:: Free , ty :: AliasTy { def_id , args , .. } ) => {
2218
2195
if cx. tcx . features ( ) . lazy_type_alias ( ) {
2219
2196
// Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
2220
2197
// we need to use `type_of`.
2221
- let path = clean_middle_path (
2222
- cx,
2223
- data. def_id ,
2224
- false ,
2225
- ThinVec :: new ( ) ,
2226
- bound_ty. rebind ( data. args ) ,
2227
- ) ;
2198
+ let path =
2199
+ clean_middle_path ( cx, def_id, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
2228
2200
Type :: Path { path }
2229
2201
} else {
2230
- 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) ;
2231
2203
clean_middle_ty ( bound_ty. rebind ( ty) , cx, None , None )
2232
2204
}
2233
2205
}
@@ -2314,18 +2286,17 @@ fn clean_middle_opaque_bounds<'tcx>(
2314
2286
let bindings: ThinVec < _ > = bounds
2315
2287
. iter ( )
2316
2288
. filter_map ( |( bound, _) | {
2317
- if let ty:: ClauseKind :: Projection ( proj) = bound. kind ( ) . skip_binder ( )
2318
- && 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 ( )
2319
2292
{
2320
2293
return Some ( AssocItemConstraint {
2321
2294
assoc : projection_to_path_segment (
2322
- // FIXME: This needs to be made resilient for `AliasTerm`s that
2323
- // are associated consts.
2324
- bound. kind ( ) . rebind ( proj. projection_term . expect_ty ( cx. tcx ) ) ,
2295
+ bound. rebind ( proj_pred. projection_term ) ,
2325
2296
cx,
2326
2297
) ,
2327
2298
kind : AssocItemConstraintKind :: Equality {
2328
- term : clean_middle_term ( bound. kind ( ) . rebind ( proj . term ) , cx) ,
2299
+ term : clean_middle_term ( bound. rebind ( proj_pred . term ) , cx) ,
2329
2300
} ,
2330
2301
} ) ;
2331
2302
}
0 commit comments